0

Need a sample working code so I can try to better understand how this works on Point of Sale application in Odoo 12.

I am trying to add a new custom field to the "pos.order.line" for use with Point of Sale application and I am not comfortable with Odoo 12 pos.

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 the 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. This "types" information 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')

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 product is added to basket.

On PoS I need:

  • Load the new model and fields;

  • Write the value to the pos.order.line when order is added to basket;

Can anyone help me please?

pmatos
  • 276
  • 4
  • 18

1 Answers1

1

You can set types_id related to product_id.product_tmpl_id.types_id and it will be filled automatically.

class PosOrderLine(models.Model):
    _inherit = "pos.order.line"

    types_id = fields.Many2one(related='product_id.product_tmpl_id.types_id', 
                               string='Product specific type')
Kenly
  • 24,317
  • 7
  • 44
  • 60
  • Dear @Kenly, Thank you very much for your help. I had to fight for some time with your code until I found that needed "store=True". I am new to both Odoo and mainly point_of_sale (JavaScript) and if you don't mind I will try to include you on my future questions. Thank you very much once again. – pmatos Mar 30 '20 at 10:47