Dear all
I am trying to add a new custom field to the "pos.order.line" for use with Point of Sale application in Odoo 12.
This new field is dependable on a new model I have created for use with products.
I added this field to the model and I need it to be automatically filled on every pos order line for every product.
It is something like the "taxes", were user selects a product and Odoo automatically set the tax information on pos order line.
For a better understanding I will try to reproduce the steps I have accomplished so far.
1. New model: for this example I will call it "Type".
This model will be filled with "several" types and added to every product I have.
class Types(models.Model):
_name = 'types'
_description = 'Sample Types Model'
code = fields.Char('Code', required=True)
name = fields.Char('Description', required=True)
2. As stated, this "types" will be added to every product I have, so, I have added a new field to "products.template" model:
class ProductTemplate(models.Model):
_inherit = "product.template"
types_id = fields.Many2one('types', string='Product specific type')
3. Since I need this value to be shown on every pos order line, I added the field to the "pos.order.line" model using the same approach:
class PosOrderLine(models.Model):
_inherit = "pos.order.line"
types_id = fields.Many2one('types', string='Product specific type'
PS: I could use another approach by "working" with "product_id" field on the "pos.order.line", but I need to keep track of the "type" used on every product line even if user changes the "type" on the product and using this approach I will keep track the "type" used on the pos order no matter if the type was changed on the product.
4. Here the problem starts.
I need to load the new model and the new field added to "product.template" and write the default "type" for every product on the "pos.order.line", when the order is confirmed.
I am trying to load the "types" model and the new "types_id" field on product.template using the following code:
var pos_model = require('point_of_sale.models');
pos_model.load_fields("types", "code", "name");
pos_model.load_fields("product.template", "types_id");
Is the code above correct?
5. Now, I need to override the method that manages the pos.order.lines, in order to automatically load the "type" field when a product is added to the basket and write it to database for every product lines included on the order.
Can anyone help me please?
Thank you very much
Best regards
PM