Hello and thanks in advance.
I am trying to create custom model to update the qty on purchase order lines. I have the following code but it is not working:
class PurchaseOrderLines(models.Model):
"""Inherited the model for add field for barcode."""
_inherit = "purchase.order.line"
barcode_scan = fields.Char(string='Product Barcode',
related='product_id.barcode', readonly=False,
help="Here you can provide the barcode for "
"the product")
@api.onchange('barcode_scan')
def _onchange_barcode_scan(self):
"""Onchange function for searching product using their barcode Including the Multi-Barcodes"""
if self.barcode_scan:
multi_barcode_id = self.env['product.template.barcode'].search([('name', '=', self.barcode_scan)])
package_barcode = self.env['product.packaging'].search([('barcode', '=', self.barcode_scan)])
product_idd = self.env['product.product'].search([('barcode', '=', self.barcode_scan)])
if multi_barcode_id:
self.product_id = multi_barcode_id.product_id
elif package_barcode:
self.product_id = package_barcode.product_id
self.product_quantity = package_barcode.qty
else:
self.product_id = product_idd
The line to update Qty is:
self.product_quantity = package_barcode.qty
the purchase line qty is always one and does not update. How can override the default odoo code in the purchase line to update the qty I need.
I have also tried using that variable and still no change. the default qty 1 is always there regardless of the qty set in the package barcode
Odoo AI suggested the following code but still no luck. odoo default actions kicks in and set the qty back to 1.