Skip to Content
Menu
This question has been flagged
2 Replies
1266 Views

hello


Ref to Odoo 17 Online


In Salse App i Want to add their is the field of the price i have extra to field B and C


how can i make Field C content is the amount of price field - the amount of the field B?


Many thanks

Avatar
Discard
Best Answer

Hi, 

Try this code:

from odoo import models, fields, api

class YourSaleModel(models.Model):
    _name = 'your.sale.model'
    _description = 'Your Sale Model'
   price_field = fields.Float(string='Price')
    field_b = fields.Float(string='Field B')
    field_c = fields.Float(string='Field C', compute='_compute_field_c', store=True)

    @api.depends('price_field', 'field_b')
    def _compute_field_c(self):
        for record in self:
            record.field_c = record.price_field - record.field_b Remember to replace 'your.sale.model' with the actual name of your model. After defining the model, you can use it in your Sale app, and the computed field field_c will be automatically updated whenever price_field or field_b changes.


Hope it helps

Avatar
Discard
Best Answer

Hi,

You can do that by using computed field, the field C need to be computed field depending on B and price_unit fields so in the C field form view:

Dependencies = B,price_unit

in Compute you will use the below code:

for record in self:

    record['C'] = record['price_unit'] + record ['B']

Avatar
Discard
Related Posts Replies Views Activity
1
Jul 25
389
2
Jul 25
677
1
Jul 25
501
1
Jul 25
478
2
Jul 25
494