Přejít na obsah
Menu
You need to be registered to interact with the community.
This question has been flagged
2 Odpovědi
4075 Zobrazení

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
Zrušit
Autor Nejlepší odpověď

"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
Zrušit
Nejlepší odpověď

Hi Daniele,

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

Thanks,

Avatar
Zrušit
Related Posts Odpovědi Zobrazení Aktivita
1
kvě 22
2086
1
srp 18
8554
1
zář 24
1726
0
bře 23
2795
1
kvě 25
1414