Giter VIP home page Giter VIP logo

Comments (7)

hbrunn avatar hbrunn commented on July 30, 2024

what you posted looks perfectly fine to me. I assume you open this in some wizard where you fill in defaults for the from and to dates? The thing is that web_widget_x2many_2d_matrix is only a widget, it takes care of displaying stuff. You need to take care of the content yourself.

So if you give the field content like

def default_get(self):
    defaults = super(yourmodel, self).default_get()
    defaults['task_id'] = [
        (0, 0, {
            'employee_id': e,
            'project_id': p,
            'planned_hours': h.
        })
        for e, p, h in {a function that generates values for all employee/project combinations}

you should see something more intersting

from web.

jjrevilla avatar jjrevilla commented on July 30, 2024

@hbrunn , Thanks for your reply.
I tried what you advised me and this is my new view:
seleccion_002

In this code i used the zip function only for save time

def default_get(self, cr, uid, fields, context=None):
        defaults = super(Manager,self).default_get(cr, uid, fields, context=None)

        employee_obj = self.pool.get('test.matrix.employee')
        employee_ids_list =  employee_obj.search(cr, uid, [], context=context)
        employee_names_list = [rec.name for rec in employee_obj.browse(
            cr, uid, employee_ids_list, context=context)]

        project_obj = self.pool.get('test.matrix.project')
        project_ids_list =  project_obj.search(cr, uid, [], context=context)
        project_names_list = [rec.name for rec in project_obj.browse(
            cr, uid, project_ids_list, context=context)]        

        defaults['task_id'] = [
            (0, 0, {
                'employee_id': e,
                'project_id': p,
                'planned_hours': h
            })
            for e, p, h in zip([employee_names_list],[project_names_list],[12,22,21])
        ]        

        return defaults

This seems good, but the only thing that i don't understand is about the values of the dictionary 'defaults['task_id']', I mean:

 defaults['task_id'] = [
            (0, 0, {
                'employee_id': e,  #e should be a list of employees o a single employee?
                'project_id': p, #p should be a list of projects o single project?
                'planned_hours': h 
            })
 ]

That's all, thanks for your advices!

from web.

hbrunn avatar hbrunn commented on July 30, 2024

a couple of things:

  • project_id and employee_id are declared as Many2one in your example, so pass the ids you have
  • the way you create your data, you'll never get a full matrix. Do something like
  defaults['task_id'] = [
      (0, 0, {
          'employee_id': e,
          'project_id': p,
          'planned_hours': 0,
      })
      for e in employee_ids_list
      for p in project_ids_list
  ]

it's two dimensional after all, so two loops.

  • you don't need the names, the widget looks that up by itself and if I remember correctly, even makes the names links that open the referenced object

Would you care to write up your findings in a PR on the addon's README.md? Then everyone has a simpler start than you had.

from web.

hbrunn avatar hbrunn commented on July 30, 2024

@jjrevilla is your question answered?

from web.

jjrevilla avatar jjrevilla commented on July 30, 2024

Yes, thanks so much for your help and time now i have a better understanding of odoo's widgets. I'm sorry for late response.

from web.

vincentcoll avatar vincentcoll commented on July 30, 2024

@hbrunn
Hi, I am having basically the same issue except I want to use it for the Landed Cost Valuation Adjustment where in value_x I want the Cost Lines and in the value_y I want the product_ids. So I had this but the form do not show at all. The values in the Many2Many are populated when I hit the compute button in the landed cost. I'm kinda lost in the process. Can you guide me?

class Load(models.Model):
    _name = 'load.load'
    _rec_name = 'load_number'
    load_lines = fields.One2many(comodel_name='load.line',
                                 inverse_name='load_id',
                                 string='Load lines')
    adjustment_lines_ids = fields.Many2many( comodel_name='load.adjustment.fees.load.lines', string='Fee Lines', compute='_compute_fee_lines')`

    @api.depends('load_lines')
    def _compute_fee_lines(self):
        fee_lines = []

        for line in self.load_lines:
            fee_lines.extend(line.adjustment_fees)

        return fee_lines`
  def compute_landed_cost(self):
        AdjustementLines = self.env['load.valuation.adjustment.lines']
        AdjustmentFees = self.env['load.adjustment.fees']
        AdjustementLines.search([('cost_id', 'in', self.ids)]).unlink()
        AdjustmentFees.search([('load_id', 'in', self.ids)]).unlink()
        AdjustmentFeeLines = self.env['load.adjustment.fees.load.lines']

        digits = dp.get_precision('Product Price')(self._cr)
        towrite_dict = {}
        for cost in self.filtered(lambda cost: cost.load_lines):
            total_qty = 0.0
            total_cost = 0.0
            total_weight = 0.0
            total_volume = 0.0
            total_line = 0.0
            all_val_line_values = cost.get_valuation_lines()
            lines = []
            for val_line_values in all_val_line_values:
                for fee_name, fee_value in val_line_values.iteritems():
                    fee = self.env['load.adjustment.fees'].create( {'load_id': cost.id, 'name': fee_name})
                    for load_line in cost.load_lines:

                        lines.append((0, 0, {
                                    'value_x': fee.id,
                                    'value_y': load_line.id,
                                    'adjustment_value': 0

                        }))

                fee = fee.update({'adjustment_lines_ids': lines}


class AdjustmentLineFees(models.Model):
    _name = 'load.adjustment.fees'
    _description = 'Stock Valuation Adjustment Fees'
    load_id = fields.Many2one(
        'load.load', 'Landed Cost',
        ondelete='cascade', required=True)
    adjustment_lines_ids = fields.Many2many(
        comodel_name='load.adjustment.fees.load.lines', string='Fee Lines')
    adjustment_fees = fields.One2many(comodel_name='load.adjustment.fees.load.lines',
                                      inverse_name='value_x',
                                      copy=True,
                                      string='Load lines')

    name = fields.Char('Fee', required=True)


class AdjustmentFeesToLoadLines(models.Model):
    _name = 'load.adjustment.fees.load.lines'
    _description = 'Stock Valuation Adjustment Fees To Load Lines'
    load_id = fields.Many2one(related='value_y.load_id')
    value_x = fields.Many2one('load.adjustment.fee', 'Fee', required=True)
    value_y = fields.Many2one('load.line', 'Load Line', required=True)
    adjustment_value = fields.Char('Value')



<div class="oe_clear"/>
                                <separator string="Valuation Adjustments"/>
                                <field name="adjustment_lines_ids"
                                       widget="x2many_2d_matrix"
                                       field_x_axis="value_x"
                                       field_y_axis="value_y"
                                       field_value = "adjustment_value"
                                       field_att_disabled="disabled"
                                       x_axis_clickable="1"
                                       y_axis_clickable="1"
                                    />
                                <div class="oe_clear"/>
                                <separator string="Valuation Adjustments"/>```

from web.

hbrunn avatar hbrunn commented on July 30, 2024

first, don't use the widget at all to inspect the values with a normal many2many widget. then, check if the values in there will form a balanced matrix at all, and then post whatever get_value gets as arguments

from web.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.