I'm a Odoo user (not developer). I have a custom module that have 2 bugs, I'm trying to understand how fix bugs, but I don't find solution. I think code interested is in model file. Module, by barcode scanning in a custom field, add product line in Order with Product, Description, Qty, Unit price, but missing taxes. If same product barcode is scanned more time, is increase quantity in same product line. First Bug issue is Not add Taxes, I have a product line without taxes. I've seen inside code, and there is not any command that invokes Taxes. Second bug issue is hold Price. The module allow to add and update price manually by custom field barcode scanning, and inside code there is command for hold last Price value update. Without this, if product is scanned again, come back to odoo price. Problems is the hold price value is not unlocked when I go out current order, So If I will create new order or update existent order, using custom module is applied Price value retained in previous order, and not odoo product price.
------------First code part:
# added the price history map
priceHistory = {}
class SaleOrder(models.Model):
"""Inherit Sale Order."""
_inherit = "sale.order"
barcode = fields.Char(string='Barcode', size=50)
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)
if corresponding_line:
corresponding_line[0].product_uom_qty += float(qty)
corresponding_line[0].price_unit = float(price) or product.list_price
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,
})
return True
Here I've tried to add:
'tax_id' : account.tax
belowe line
'price_unit': float(price) or product.list_price,
but not work.
------------ Last code part
if product_id:
# get the history price
if price_position == -1:
#if priceHistory.has_key(product_id.id):
if product_id.id in priceHistory.keys():
price = priceHistory[product_id.id]
self._add_product(product_id, qty, price)
self.barcode = barcode = None
#save the product price
priceHistory[product_id.id] = price
return
Here, if I delete:
#save the product price
priceHistory[product_id.id] = price
I can solve Price value retained issue but I create a new issue: If module add a product with a new price matched, and subsequently add same product again Without price matched, in same product line it's increase quantity but previous Price value, is replaced by odoo price. So I need to hold last product price updated manually by my custom module during adding products (how currently module do), but priceHistory must be erase when I go out current Order. Can anyone give any suggestion for solve this issues? Thank you very much
I've forgot, in original file after code which i've posted, there is also this code part:
'''
class SaleOrderLine(models.Model):
"""Inherit Sale Order Line."""
_inherit = "sale.order.line"
barcode = fields.Char(string='Barcode')
'''
Maybe can influence something?