From b483e2d13869656f614c38c577cd2796e93e97af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Mon, 4 Feb 2013 20:09:51 +0100 Subject: [PATCH] Use asset account when creating invoice from purchase review636003 --- __init__.py | 2 ++ purchase.py | 32 ++++++++++++++++++++++++++++++++ tryton.cfg | 2 ++ 3 files changed, 36 insertions(+) create mode 100644 purchase.py diff --git a/__init__.py b/__init__.py index 73ee41b460..8025921e83 100644 --- a/__init__.py +++ b/__init__.py @@ -5,6 +5,7 @@ from .asset import * from .product import * from .invoice import * from .account import * +from .purchase import * def register(): @@ -20,6 +21,7 @@ def register(): InvoiceLine, Configuration, Move, + PurchaseLine, module='account_asset', type_='model') Pool.register( CreateMoves, diff --git a/purchase.py b/purchase.py new file mode 100644 index 0000000000..74bca0d600 --- /dev/null +++ b/purchase.py @@ -0,0 +1,32 @@ +# 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.pool import PoolMeta + +__all__ = ['PurchaseLine'] +__metaclass__ = PoolMeta + + +class PurchaseLine: + __name__ = 'purchase.line' + + @classmethod + def __setup__(cls): + super(PurchaseLine, cls).__setup__() + cls._error_messages.update({ + 'missing_account_asset': ('It misses ' + 'an "Account Asset" on product "%s"!'), + }) + + def get_invoice_line(self, invoice_type): + invoice_lines = super(PurchaseLine, self).get_invoice_line( + invoice_type) + if (self.product + and self.product.type == 'assets' + and self.product.depreciable): + for invoice_line in invoice_lines: + if invoice_line.product == self.product: + invoice_line.account = self.product.account_asset_used + if not invoice_line.account: + self.raise_user_error('missing_account_asset', + error_args=(self.product.rec_name,)) + return invoice_lines diff --git a/tryton.cfg b/tryton.cfg index c053f986ca..318e4190f4 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -6,6 +6,8 @@ depends = account product account_invoice +extras_depend = + purchase xml = asset.xml product.xml