Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
5736 Lượt xem

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

Ảnh đại diện
Huỷ bỏ

Hi please add your code with the question.

Tác giả

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

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 25
5672
2
thg 10 25
8382
2
thg 11 24
29221
2
thg 5 24
8058
3
thg 3 24
7461