/
stock.py
38 lines (29 loc) · 1.17 KB
/
stock.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
# -*- coding: utf-8 -*-
# Copyright 2013 Julius Network Solutions
# Copyright 2015 Clear Corp
# Copyright 2016 OpenSynergy Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from openerp import fields, models, api
class StockMove(models.Model):
_inherit = "stock.move"
analytic_account_id = fields.Many2one(
string='Analytic Account',
comodel_name='account.analytic.account',
)
class StockQuant(models.Model):
_inherit = "stock.quant"
@api.model
def _prepare_account_move_line(self, move, qty, cost,
credit_account_id, debit_account_id):
res = super(StockQuant, self)._prepare_account_move_line(
move, qty, cost, credit_account_id, debit_account_id)
# Add analytic account in debit line
if not move.analytic_account_id:
return res
for num in range(0, 2):
if res[num][2]["account_id"] != move.product_id.\
categ_id.property_stock_valuation_account_id.id:
res[num][2].update({
'analytic_account_id': move.analytic_account_id.id,
})
return res