Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda

I'm a Odoo v.13 CE user (not developer). I have a custom module that have many bugs, I'm trying to understand how fix bug, but I don't find solution.

Module, by barcode scanning in a custom field, add product line in Order with Product, Description, Qty, Unit price, and taxes. If same product barcode is scanned more time, is increase quantity in same product line.   Bugs are: 

1. In Purchase order, is not call correct Price_unit of supplier selected. It apply price 0 always.

2. In Sale order, is not call correct Price_unit of Pricelist selected, It apply default list_price always.

Please, someone can help me to fix this, and say me correct code to add? I'm not a developer, I don't know nothing about code and programming.

Thanks

----------Purchase Order code

def _add_product(self, product, qty, price):
"""Add line or update qty and price based on barcode."""
corresponding_line = self.order_line.filtered(lambda r: r.product_id.id == product.id)
taxes = product.supplier_taxes_id.filtered(lambda t: t.company_id.id == self.company_id.id)
taxes_ids = taxes.ids
if corresponding_line:
corresponding_line[0].product_qty += float(qty)
corresponding_line[0].price_unit = float(price) or product.price
if self.partner_id and self.fiscal_position_id:
taxes_ids = self.fiscal_position_id.map_tax(taxes, product, self.partner_id).ids
else:
self.order_line += self.order_line.new({
'product_id': product.id,
'product_qty': qty,
'date_planned': fields.Datetime.to_string(datetime.datetime.now() - dateutil.relativedelta.relativedelta(months=1)),
'name': product.name,
'product_uom': product.uom_id.id,
'price_unit': float(price) or product.price,
'taxes_id': [(6, 0, taxes_ids)],
})
return True

----------Sale Order code

def _add_product(self, product, qty, price):
"""Add line or update qty and price based on barcode."""
corresponding_line = self.order_line.filtered(lambda r: r.product_id.id == product.id)
taxes = product.taxes_id.filtered(lambda t: t.company_id.id == self.company_id.id)
taxes_ids = taxes.ids
if corresponding_line:
corresponding_line[0].product_uom_qty += float(qty)
corresponding_line[0].price_unit = float(price) or product.list_price
if self.partner_id and self.fiscal_position_id:
taxes_ids = self.fiscal_position_id.map_tax(taxes, product, self.partner_id).ids
else:
self.order_line += self.order_line.new({
'product_id': product.id,
'product_uom_qty': qty,
'name': product.name,
'product_uom': product.uom_id.id,
'price_unit': float(price) or product.list_price,
'tax_id': [(6, 0, taxes_ids)],
})

return True
Avatar
Buang
Penulis Jawaban Terbai

"You can try to update dictionary using onchange method of product."

Hi Krutarth. thanks for your help. I'm not a developer, so I don't understand very well generic suggestion, it's more appreciate if you can write code.

Anyway, I've tried in Purchase Order code, to add:

@api.onchange('product')

before code

def _add_product(self, product, qty, price):

if you mean this, but is not change nothing. In purchase order supplier price is always 0

Thanks


Avatar
Buang
Jawaban Terbai

Hi Daniele,

You can try to update dictionary using onchange method of product.

Thanks,

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Mei 22
1819
1
Agu 18
8313
1
Sep 24
1428
0
Mar 23
2496
1
Mei 25
1001