pythonodooodoo-12

How to make Wizards take a variable value from a model?


I have a problem which I'm not finding the solution to. I have a module which works on property management. I have three files that work together, one with infom one a wizard and the other the invoice view. The wizard takes some info and places to the invoice tree view.

I have quite smth very specific taken from the model which is an inheritance of "product.template" which has a variable (field: Many2one) called incharge_id. I need to take this variable to the wizard which processes the invoice tree view. I tried so many things although no luck. This is the field in the product.template.

incharge_id = fields.Many2one('res.partner', string="In Charge")

I need to take it here:

invoice_obj.sudo().create({'partner_id': self.partner_id.id,
                                                   'currency_id': self.property_id.monedha2.id,
                                                   'incharge_id': incharge.id,
                                                   'account_id': self.partner_id.property_account_receivable_id.id,
                                                   'origin': self.property_id.id,
                                                   'date_invoice': invoice_date,
                                                   'from_property': True,
                                                   'selection': origin + ", " + str(selection) + ", " + str(pagesa),
                                                   'date_due': due_date,
                                                   'invoice_line_ids': [(0, 0, {
                                                       'product_id': product_id.id,
                                                       'name': product_id.name,
                                                       'price_unit': price,
                                                       'quantity': 1,
                                                       'origin': product_id.name + " " + origin,
                                                       'account_id': account_id,
                                                   })],
                                                   })

I'd appreciate every help!


Solution

  • You have taken product_id which means you can take incharge_id as well.

    'product_id': product_id.id
    

    Check the product_id whether it's from class product.product or product.template.

    If product.template -->

    'incharge_id': product_id.incharge_id.id
    

    incase product.product -->

    'incharge_id': product_id.product_tmpl_id.incharge_id.id