forked from tryton/account_stock_anglo_saxon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.py
84 lines (67 loc) · 2.65 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond import backend
from trytond.model import fields
from trytond.pyson import Eval
from trytond.pool import PoolMeta, Pool
from trytond.modules.account_product.product import (
account_used, template_property)
__all__ = ['Category', 'CategoryAccount', 'Template', 'Product']
class Category(metaclass=PoolMeta):
__name__ = 'product.category'
account_cogs = fields.MultiValue(fields.Many2One('account.account',
'Account Cost of Goods Sold', domain=[
('kind', '!=', 'view'),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}, ).get('company')
| Eval('account_parent')
| ~Eval('accounting', False)),
},
depends=['account_parent', 'accounting']))
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'account_cogs':
return pool.get('product.category.account')
return super(Category, cls).multivalue_model(field)
@property
@account_used('account_cogs')
def account_cogs_used(self):
pass
class CategoryAccount(metaclass=PoolMeta):
__name__ = 'product.category.account'
account_cogs = fields.Many2One(
'account.account', "Account Cost of Goods Sold",
domain=[
('kind', '!=', 'view'),
('company', '=', Eval('company', -1)),
],
depends=['company'])
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
exist = TableHandler.table_exist(cls._table)
if exist:
table = cls.__table_handler__(module_name)
exist &= table.column_exist('account_cogs')
super(CategoryAccount, cls).__register__(module_name)
if not exist:
# Re-migration
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append('account_cogs')
value_names.append('account_cogs')
super(CategoryAccount, cls)._migrate_property(
field_names, value_names, fields)
class Template(metaclass=PoolMeta):
__name__ = 'product.template'
@property
@account_used('account_cogs', 'account_category')
def account_cogs_used(self):
pass
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
account_cogs_used = template_property('account_cogs_used')