forked from OCA/product-attribute
-
Notifications
You must be signed in to change notification settings - Fork 1
/
pricelist.py
102 lines (86 loc) · 3.14 KB
/
pricelist.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 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
PRICE_GRID_HELP = _("""Define if the price list items are filled
from product form with a grid of specific values
for each product""")
class ProductPricelist(models.Model):
_inherit = 'product.pricelist'
price_grid = fields.Boolean(
string='Product Price Grid',
help=PRICE_GRID_HELP)
class ProductPricelistVersion(models.Model):
_inherit = 'product.pricelist.version'
@api.depends('tmpl_in_count')
def count_products(self):
PPItem_m = self.env['product.pricelist.item']
for record in self:
if not isinstance(self.id, models.NewId):
predicats = {
'tmpl_in_count': ('product_tmpl_id', '!=', False),
}
version_domain = [('price_version_id', '=', record.id)]
for field, predicat in predicats.items():
domain = list(version_domain)
domain.append(predicat)
self[field] = PPItem_m.search_count(domain)
price_grid = fields.Boolean(
related='pricelist_id.price_grid',
domain=[('price_surcharge', '=', 0)],
store=True,
help=PRICE_GRID_HELP)
tmpl_in_count = fields.Integer(
string="Template with this Version",
compute='count_products',
help="Number of Product Template with this Pricelist version")
item_grid_ids = fields.One2many(
'product.pricelist.item',
'price_version_id')
@api.multi
def button_template_in_version(self):
self.ensure_one()
domain = [('pricelist_item_ids.price_version_id', '=', self.id)]
return {
'type': 'ir.actions.act_window',
'target': 'current',
'domain': domain,
'view_mode': 'tree,form',
'res_model': 'product.template',
}
class ProductPricelistItem(models.Model):
_inherit = 'product.pricelist.item'
date_end = fields.Date(
related='price_version_id.date_end',
readonly=True)
currency_name = fields.Many2one(
related='price_version_id.pricelist_id.currency_id',
readonly=True)
related_sequence = fields.Integer(
String='Sequence',
related="sequence")
@api.multi
def button_product(self):
self.ensure_one()
if self.product_tmpl_id:
product = self.product_tmpl_id
else:
product = self.product_id.product_tmpl_id
return {
'type': 'ir.actions.act_window',
'target': 'current',
'name': 'Product',
'view_mode': 'form',
'res_id': product.id,
'res_model': 'product.template',
}
@api.model
def create(self, vals):
if self.env['product.pricelist.version'].browse(
vals['price_version_id']).price_grid:
vals.update({
'price_discount': -1,
'sequence': 1,
'base': 1,
})
return super(ProductPricelistItem, self).create(vals)