Debian Codegraph @

addons/point_of_sale/models/product_attribute.py

raw
1 from odoo import api, fields, models
2
3
4 class ProductAttribute(models.Model):
5 _name = 'product.attribute'
6 _inherit = ['product.attribute', 'pos.load.mixin']
7
8 @api.model
9 def _load_pos_data_fields(self, config):
10 return ['name', 'display_type', 'create_variant']
11
12
13 class ProductAttributeCustomValue(models.Model):
14 _name = 'product.attribute.custom.value'
15 _inherit = ["product.attribute.custom.value", "pos.load.mixin"]
16
17 pos_order_line_id = fields.Many2one('pos.order.line', string="PoS Order Line", ondelete='cascade', index='btree_not_null')
18
19 @api.model
20 def _load_pos_data_domain(self, data, config):
21 return [('pos_order_line_id', 'in', [line['id'] for line in data['pos.order.line']])]
22
23 @api.model
24 def _load_pos_data_fields(self, config):
25 return ['custom_value', 'custom_product_template_attribute_value_id', 'pos_order_line_id', 'write_date']
26
27
28 class ProductTemplateAttributeLine(models.Model):
29 _name = 'product.template.attribute.line'
30 _inherit = ['product.template.attribute.line', 'pos.load.mixin']
31
32 @api.model
33 def _load_pos_data_fields(self, config):
34 return ['display_name', 'attribute_id', 'product_template_value_ids']
35
36 @api.model
37 def _load_pos_data_domain(self, data, config):
38 loaded_product_tmpl_ids = list({p['id'] for p in data['product.template']})
39 return [('product_tmpl_id', 'in', loaded_product_tmpl_ids)]
40
41
42 class ProductTemplateAttributeValue(models.Model):
43 _name = 'product.template.attribute.value'
44 _inherit = ['product.template.attribute.value', 'pos.load.mixin']
45
46 @api.model
47 def _load_pos_data_domain(self, data, config):
48 ptav_ids = {ptav_id for p in data['product.product'] for ptav_id in p['product_template_variant_value_ids']}
49 ptav_ids.update({ptav_id for ptal in data['product.template.attribute.line'] for ptav_id in ptal['product_template_value_ids']})
50 return [
51 ('ptav_active', '=', True),
52 ('attribute_id', 'in', [attr['id'] for attr in data['product.attribute']]),
53 ('id', 'in', list(ptav_ids)),
54 ]
55
56 @api.model
57 def _load_pos_data_fields(self, config):
58 return ['attribute_id', 'attribute_line_id', 'product_attribute_value_id', 'price_extra', 'name', 'is_custom', 'html_color', 'image', 'exclude_for']
59
60
61 class ProductTemplateAttributeExclusion(models.Model):
62 _name = 'product.template.attribute.exclusion'
63 _inherit = ['product.template.attribute.exclusion', 'pos.load.mixin']
64
65 @api.model
66 def _load_pos_data_domain(self, data, config):
67 loaded_product_tmpl_ids = list({p['id'] for p in data['product.template']})
68 loaded_ptav_ids = list({ptav['id'] for ptav in data['product.template.attribute.value']})
69 return [('product_tmpl_id', 'in', loaded_product_tmpl_ids), ('product_template_attribute_value_id', 'in', loaded_ptav_ids)]
70
71 @api.model
72 def _load_pos_data_fields(self, config):
73 return ['value_ids', 'product_template_attribute_value_id']