changeset c6aee4a3c5b9 in modules/account_invoice_stock:default
details:
https://hg.tryton.org/modules/account_invoice_stock?cmd=changeset&node=c6aee4a3c5b9
description:
Add warehouse to invoice line
This ensures that the cost price used for COGS lines come from the right
warehouse when it is computed per warehouse.
issue10568
review362161002
diffstat:
CHANGELOG | 2 ++
account.py | 14 ++++++++++++++
2 files changed, 16 insertions(+), 0 deletions(-)
diffs (40 lines):
diff -r d8836958116f -r c6aee4a3c5b9 CHANGELOG
--- a/CHANGELOG Sun Jul 04 17:54:46 2021 +0200
+++ b/CHANGELOG Thu Jul 29 09:06:38 2021 +0200
@@ -1,3 +1,5 @@
+* Compute warehouse for invoice line
+
Version 6.0.0 - 2021-05-03
* Bug fixes (see mercurial logs for details)
* Manage price correction from supplier invoice
diff -r d8836958116f -r c6aee4a3c5b9 account.py
--- a/account.py Sun Jul 04 17:54:46 2021 +0200
+++ b/account.py Thu Jul 29 09:06:38 2021 +0200
@@ -31,6 +31,9 @@
class InvoiceLine(metaclass=PoolMeta):
__name__ = 'account.invoice.line'
+
+ warehouse = fields.Function(fields.Many2One(
+ 'stock.location', "Warehouse"), 'get_warehouse')
stock_moves = fields.Many2Many(
'account.invoice.line-stock.move', 'invoice_line', 'stock_move',
"Stock Moves",
@@ -72,6 +75,17 @@
def default_correction(cls):
return False
+ def get_warehouse(self, name):
+ if (self.invoice_type == 'out'
+ or (self.invoice and self.invoice.type) == 'out'):
+ warehouses = set(filter(None, [
+ m.from_location.warehouse for m in self.stock_moves]))
+ else:
+ warehouses = set(filter(None, [
+ m.to_location.warehouse for m in self.stock_moves]))
+ if warehouses:
+ return list(warehouses)[0].id
+
@property
def moved_quantity(self):
'The quantity from linked stock moves in line unit'