-
-
Notifications
You must be signed in to change notification settings - Fork 274
Expand file tree
/
Copy pathstock_move.py
More file actions
124 lines (116 loc) · 4.74 KB
/
Copy pathstock_move.py
File metadata and controls
124 lines (116 loc) · 4.74 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# © 2019 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2019 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import exceptions, models
class StockMove(models.Model):
_inherit = "stock.move"
def _generate_valuation_lines_data(
self,
partner_id,
qty,
debit_value,
credit_value,
debit_account_id,
credit_account_id,
svl_id,
description,
):
res = super()._generate_valuation_lines_data(
partner_id,
qty,
debit_value,
credit_value,
debit_account_id,
credit_account_id,
svl_id,
description,
)
if res:
debit_line_vals = res.get("debit_line_vals")
credit_line_vals = res.get("credit_line_vals")
price_diff_line_vals = res.get("price_diff_line_vals", {})
if (
self.operating_unit_id
and self.operating_unit_dest_id
and self.operating_unit_id != self.operating_unit_dest_id
and debit_line_vals["account_id"] != credit_line_vals["account_id"]
):
raise exceptions.UserError(
self.env._(
"You cannot create stock moves involving separate source"
" and destination accounts related to different "
"operating units."
)
)
if not self.operating_unit_dest_id and not self.operating_unit_id:
ou_id = (
self.picking_id.picking_type_id.warehouse_id.operating_unit_id.id
)
else:
ou_id = False
debit_line_vals["operating_unit_id"] = (
ou_id or self.operating_unit_dest_id.id or self.operating_unit_id.id
)
credit_line_vals["operating_unit_id"] = (
ou_id or self.operating_unit_id.id or self.operating_unit_dest_id.id
)
rslt = {
"credit_line_vals": credit_line_vals,
"debit_line_vals": debit_line_vals,
}
if price_diff_line_vals:
price_diff_line_vals["operating_unit_id"] = (
ou_id or self.operating_unit_id.id or self.operating_unit_dest_id.id
)
rslt["price_diff_line_vals"] = price_diff_line_vals
return rslt
return res
def _action_done(self, cancel_backorder=False):
"""
Generate accounting moves if the product being moved is subject
to real_time valuation tracking,
and the source or destination location are
a transit location or is outside of the company or the source or
destination locations belong to different operating units.
"""
res = super()._action_done(cancel_backorder)
for move in self:
if move.product_id.valuation == "real_time":
# Inter-operating unit moves do not accept to
# from/to non-internal location
if move.location_id.company_id and (
move.location_id.company_id == move.location_dest_id.company_id
and move.operating_unit_id != move.operating_unit_dest_id
):
(
journal_id,
acc_src,
acc_dest,
acc_valuation,
) = move._get_accounting_data_for_valuation()
move_lines = move._prepare_account_move_line(
move.product_qty,
move.product_id.standard_price,
acc_valuation,
acc_valuation,
self.env._("%s - OU Move") % move.product_id.display_name,
)
am = (
self.env["account.move"]
.with_context(
company_id=move.company_id.id,
)
.create(
{
"journal_id": journal_id,
"line_ids": move_lines,
"company_id": move.company_id.id,
"ref": move.picking_id and move.picking_id.name,
"stock_move_id": move.id,
}
)
.with_company(move.location_id.company_id.id)
)
am.action_post()
return res