Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
1 Odgovori
14588 Prikazi

Hello All

I have a One2many field in inventory for product pack. And I want that all fields values of that One2many field should update in fields of One2many field in sales order, row and column wise. So, Anyone can help me.

My Python code is here:

class ProductTemplate(models.Model):

    _inherit = "product.template"

 product_pack = fields.One2many('product.pack', 'template_id', string='Product Pack', copy=True)

class ProductDesign(models.Model):

    _description = 'Product Pack'

    _name = "product.pack"

    _rec_name = "product_id"


    check_option = fields.Boolean('#')

    template_id = fields.Many2one('product.template', string='Template', required="True", ondelete='cascade', index=True, copy=True)

    product_id = fields.Many2one('product.product', string='Product', required="True", domain="[('is_pack','=',False)]")

    services = fields.Many2one('gold.service')

    qty = fields.Integer('Quantity', default=1)

Here in 'wizard' (One2many field table) i want to update all fields (row and column) of product_pack


class SalePackWizard(models.TransientModel):

    _name = "sale.pack.wizard"

    _description = "Sale Pack Wizard"

 product_id = fields.Many2one('product.product', string="Product Pack", required=True, domain="[('is_pack','=',True)]")

    wizard = fields.One2many('product.gold','service')

 @api.onchange('product_id')

    def _onchange_product_pack_name(self):

         for w in self.product_id.product_pack:

            for s in w:

                print "s:", s.product_id.name, s.services, s.qty

                r = []

                print"r:", r


class ProductDesign(models.Model):

    _description = 'Product Pack'

    _name = "product.gold"

    _rec_name = "products_ids"


    service= fields.Many2one('product.val', string='Templates', required="True", ondelete='cascade', index=True, copy=True)

    check_box = fields.Boolean('#')

    products_ids = fields.Many2one('product.product', string='Product', required="True", domain="[('is_pack','=',False)]")

    services = fields.Many2one('gold.service')

    qtyy = fields.Integer('Quantity', default=1)

Avatar
Opusti
Avtor Best Answer

Hello all, Problem Solved.

Here is the function code of problem:

wizard = fields.One2many('product.gold','service',change_default=True, default=_onchange_action_product_add)


@api.onchange('product_id')

    def _onchange_action_product_add(self):

        res = self.product_id.product_pack

        r = []

        value = {}

        for var in self.product_id.product_pack:

            print "var:::", var

            for line in self.product_id.product_pack:

                print "line:::", line , line.product_id, line.product_id.name, line.qty, line.services, line.id

                data = {'products_ids': line.product_id.id,

                        'service':var.id, #many2one child field from one2many field

                        'services':line.services,

                        'qtyy': line.qty

                        }

                print "data:", data

                r.append((0, 0, data))

                print "r.append", r.append, r

                #return data

            value.update(wizard=r)

            return {'value': value}

Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
0
apr. 20
4255
1
dec. 21
6664
1
jul. 19
3798
0
okt. 17
2835
2
okt. 17
4700