user2379186
user2379186

Reputation: 431

Odoo retrieve field from other module

Odoo 10

I am trying to copy a field from the products to the Sales order. The field in the products is called default_code. I've tried copying code from the Sales order module as its already getting unit price and tax etc. but cannot get it working.

from odoo import api, models, fields

class myfieldsinsaleorder(models.Model):

    _inherit = 'sale.order.line'

    squaremtr = fields.Float("SQ Meter Required")
    boxes = fields.Float("Suggested Boxes")
    squarebox = fields.Char("Meters Per Box")

    @api.onchange('product_id', 'default_code', 'price_unit', 'product_uom', 'product_uom_qty', 'tax_id')
    def _onchange_discount(self):
        self.discount = 0.0
        self.squarebox = 'default_code'

What it is doing now is inserting default_code text but not the values of the field

Upvotes: 2

Views: 652

Answers (2)

Charif DZ
Charif DZ

Reputation: 14721

you should use this:

self.squarebox = self.product_id.default_code

when you do this :

self.squarebox = 'default_code'

it's like : self.squarebox = 'string not a value of the field'

Upvotes: 1

dccdany
dccdany

Reputation: 836

You are setting a string instead of the field, try this:

self.squarebox = self.product_id.default_code

Upvotes: 1

Related Questions