Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
14591 Widoki

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)

Awatar
Odrzuć
Autor Najlepsza odpowiedź

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}

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
kwi 20
4255
1
gru 21
6666
1
lip 19
3798
0
paź 17
2835
2
paź 17
4701