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

Hello, I added a new field to the model sale.order.line. When creating new record, field is not saved.

My code:


class SaleOrderLine(models.Model):

    _inherit = "sale.order.line"


    calculation = fields.Float(string='Cena kalkulacji', readonly=True, store=True)

    

    @api.onchange('product_uom', 'product_uom_qty')

    def product_uom_change(self):

        if not self.product_uom or not self.product_id:

            self.price_unit = 0.0

            self.calculation = 0.0

            return

        if self.order_id.pricelist_id and self.order_id.partner_id:

            product = self.product_id.with_context(

                lang=self.order_id.partner_id.lang,

                partner=self.order_id.partner_id,

                quantity=self.product_uom_qty,

                date=self.order_id.date_order,

                pricelist=self.order_id.pricelist_id.id,

                uom=self.product_uom.id,

                fiscal_position=self.env.context.get('fiscal_position')

            )

            self.price_unit = self.env['account.tax']._fix_tax_included_price_company(self._get_display_price(product), product.taxes_id, self.tax_id, self.company_id)

            self.calculation = self.env['account.tax']._fix_tax_included_price_company(self._get_display_price(product), product.taxes_id, self.tax_id, self.company_id)            


Awatar
Odrzuć
Najlepsza odpowiedź

Hi, 

Make sure that the onchange event/function gst triggered. It seems the value to the field is written inside the onchange function for the field product_uom, so just make sure that the function is getting executed while the value of the field product_uom is changing.

You can add some print statement or logger notes to check the function execution.


Thanks

Awatar
Odrzuć
Autor Najlepsza odpowiedź

If you change the value of a readonly field in onchange method, on save it will not be stored in the database. In order to do that you would need to override create/write methods where you would need to update the values dictionary with this value before creation.

In xml for field: force_save="1"


Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
1
lut 22
2922
2
kwi 22
3425
3
maj 20
11661
5
gru 19
5381
1
sty 23
7003