forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathproduct.py
67 lines (55 loc) · 2 KB
/
product.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# coding: utf-8
# © 2015 David BEAL @ Akretion
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import api, fields, models
class ProductTemplate(models.Model):
_inherit = 'product.template'
def _default_pricelist_item_ids(self):
return self.default_pricelist_item_ids()
pricelist_item_ids = fields.One2many(
'product.pricelist.item',
'product_tmpl_id',
string='Pricelist Items',
default=_default_pricelist_item_ids,
help="These prices are defined with absolute values\n"
"(no calculation with discount)"
)
def get_pricelist_version_domain(self):
return [('pricelist_id.price_grid', '=', True)]
def get_default_pricelist_item_vals(self, version):
return {
'price_version_id': version.id,
'price_discount': -1,
'base': 1,
}
def default_pricelist_item_ids(self):
versions = self.env['product.pricelist.version'].search(
self.get_pricelist_version_domain())
res = []
for version in versions:
res.append(self.get_default_pricelist_item_vals(version))
return res
@api.model
def create(self, vals):
if 'pricelist_item_ids' in vals:
self.create_or_write_pricelist(vals['pricelist_item_ids'])
return super(ProductTemplate, self).create(vals)
@api.multi
def write(self, vals):
if 'pricelist_item_ids' in vals:
self.create_or_write_pricelist(vals['pricelist_item_ids'])
return super(ProductTemplate, self).write(vals)
@api.model
def create_or_write_pricelist(self, pricelist_item_vals):
for version in pricelist_item_vals:
if version[2]:
self.update_pricelist_values(version[2])
return True
@api.model
def update_pricelist_values(self, vals):
vals.update({
'price_discount': -1,
'sequence': 1,
'base': 1,
})
return True