This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaccount.py
61 lines (49 loc) · 1.84 KB
/
account.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
# 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.model import ModelView, Workflow
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
class Invoice(metaclass=PoolMeta):
__name__ = 'account.invoice'
@classmethod
@ModelView.button
@Workflow.transition('posted')
def post(cls, invoices):
pool = Pool()
Move = pool.get('stock.move')
transaction = Transaction()
context = transaction.context
super().post(invoices)
moves = sum(
(l.stock_component_moves for i in invoices for l in i.lines), [])
if moves:
with transaction.set_context(
queue_batch=context.get('queue_batch', True)):
Move.__queue__.update_unit_price(moves)
class InvoiceLine(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
@property
def stock_component_moves(self):
return []
class InvoiceLineSale(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
@property
def stock_component_moves(self):
pool = Pool()
SaleLine = pool.get('sale.line')
moves = super().stock_component_moves
if isinstance(self.origin, SaleLine):
for component in self.origin.components:
moves.extend(component.moves)
return moves
class InvoiceLinePurchase(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
@property
def stock_component_moves(self):
pool = Pool()
PurchaseLine = pool.get('purchase.line')
moves = super().stock_component_moves
if isinstance(self.origin, PurchaseLine):
for component in self.origin.components:
moves.extend(component.moves)
return moves