تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
3 الردود
5728 أدوات العرض

I have new field in sale order line as mrp. I need to calculate  price_unit as

price_unit= mrp- discount 

When i use  this calculation, discount always becomes 0.00 whatever the discount value is, then price_unit become the mrp value. But  when i  put 
price _unit= mrp- 25 

this  gives the actual answer. But  i need to make  calculation dynamic. How  can I make it possible sir

الصورة الرمزية
إهمال

Hi please add your code with the question.

الكاتب

Code:

mrp=fields.Float(string='MRP')

price_unit = fields.Float('Unit Price',compute='compute_unit', required=True, default=0.0)

discount = fields.Float(string='Discount (Rs.)')

@api.depends('mrp','discount','price_unit')

def compute_unit(self):

for line in self

line.price_unit = line.mrp - line.discount

أفضل إجابة

Hi Sarina,

I think it would be better to post your code next time, but the following code will solve your problem (ref: https://github.com/odoo/odoo/blob/65f5fc6bf8442fc7004d0fc8e006184359f0fe4e/addons/sale/models/sale.py#L988-L995).

@api.onchange('product_id', 'price_unit', 'product_uom', 'product_uom_qty', 'tax_id')

    def _onchange_discount(self):
        self.discount = 0.0
        if not (self.product_id and self.product_uom and
                self.order_id.partner_id and self.order_id.pricelist_id and
                self.order_id.pricelist_id.discount_policy == 'without_discount' and
                self.env.user.has_group('sale.group_discount_per_so_line')):
            return

Hence, whether you change the price_unit field, the above method will be triggered as well and the discount will be reset to 0.

Best regards,

Tim

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
2
يوليو 25
5655
2
أكتوبر 25
8377
2
نوفمبر 24
29217
2
مايو 24
8055
3
مارس 24
7448