forked from OCA/purchase-workflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.py
75 lines (65 loc) · 2.93 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
# -*- coding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2010-2013 Camptocamp (<http://www.camptocamp.com>)
# Authors: Ferdinand Gasauer, Joel Grand-Guillaume
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm, fields
from openerp.tools.translate import _
class product_template(orm.Model):
_inherit = "product.template"
_columns = {
'landed_cost_type': fields.selection(
[('value', 'Value'),
('per_unit', 'Quantity'),
('none', 'None')],
'Distribution Type',
help="Used if this product is landed costs: "
"If landed costs are defined for purchase orders or pickings, "
"this indicates how the costs are distributed to the lines"),
}
_defaults = {
'landed_cost_type':
lambda self, cr, uid, context: context.get('landed_cost_type')
}
class product_product(orm.Model):
_inherit = "product.product"
def _choose_exp_account_from(self, cr, uid, product, fiscal_position=False,
context=None):
""" Method to compute the expense account to chose based on product and
fiscal position.
Used in invoice creation and on_change of landed costs.
Taken from method : _choose_account_from_po_line of purchase.py in
purchase module.
"""
fiscal_obj = self.pool.get('account.fiscal.position')
property_obj = self.pool.get('ir.property')
if product:
acc_id = product.property_account_expense.id
if not acc_id:
acc_id = product.categ_id.property_account_expense_categ.id
if not acc_id:
raise orm.except_orm(
_('Error!'),
_('Define expense account for this company: "%s" (id:%d).')
% (product.name, product.id,))
else:
acc_id = property_obj.get(cr, uid,
'property_account_expense_categ',
'product.category').id
return fiscal_obj.map_account(cr, uid, fiscal_position, acc_id)