changeset f160c38addd9 in modules/analytic_purchase:default
details:
https://hg.tryton.org/modules/analytic_purchase?cmd=changeset;node=f160c38addd9
description:
Remove mandatory on analytic roots
Having required field managed by user breaks automated workflows.
issue7605
review70531002
diffstat:
__init__.py | 7 ++--
purchase.py | 44 -------------------------------
tests/scenario_analytic_purchase.rst | 50 ++---------------------------------
3 files changed, 7 insertions(+), 94 deletions(-)
diffs (178 lines):
diff -r f936eb8c3c9c -r f160c38addd9 __init__.py
--- a/__init__.py Sat Jan 26 01:10:47 2019 +0100
+++ b/__init__.py Mon Feb 18 18:39:29 2019 +0100
@@ -2,12 +2,11 @@
# this repository contains the full copyright notices and license terms.
from trytond.pool import Pool
-from .purchase import *
+from . import purchase
def register():
Pool.register(
- Purchase,
- PurchaseLine,
- AnalyticAccountEntry,
+ purchase.PurchaseLine,
+ purchase.AnalyticAccountEntry,
module='analytic_purchase', type_='model')
diff -r f936eb8c3c9c -r f160c38addd9 purchase.py
--- a/purchase.py Sat Jan 26 01:10:47 2019 +0100
+++ b/purchase.py Mon Feb 18 18:39:29 2019 +0100
@@ -1,42 +1,10 @@
# 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.i18n import gettext
from trytond.model import fields
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval, If
from trytond.modules.analytic_account import AnalyticMixin
-from trytond.modules.purchase.exceptions import PurchaseQuotationError
-
-__all__ = ['Purchase', 'PurchaseLine', 'AnalyticAccountEntry']
-
-
-class Purchase(metaclass=PoolMeta):
- __name__ = "purchase.purchase"
-
- def check_for_quotation(self):
- pool = Pool()
- Account = pool.get('analytic_account.account')
- mandatory_roots = {a for a in Account.search([
- ('type', '=', 'root'),
- ('mandatory', '=', True),
- ])}
-
- super(Purchase, self).check_for_quotation()
-
- for line in self.lines:
- if line.type != 'line':
- continue
- analytic_roots = {e.root for e in line.analytic_accounts
- if e.account}
- if not mandatory_roots <= analytic_roots:
- raise PurchaseQuotationError(
- gettext('analytic_purchase'
- '.msg_analytic_account_required_for_quotation',
- purchase=self.rec_name,
- line=line.rec_name,
- roots=', '.join(x.rec_name
- for x in mandatory_roots - analytic_roots)))
class PurchaseLine(AnalyticMixin, metaclass=PoolMeta):
@@ -79,18 +47,6 @@
return origins + ['purchase.line']
@fields.depends('origin')
- def on_change_with_required(self, name=None):
- pool = Pool()
- PurchaseLine = pool.get('purchase.line')
- required = super(AnalyticAccountEntry, self).on_change_with_required(
- name)
- if isinstance(self.origin, PurchaseLine):
- if (not self.origin.purchase
- or self.origin.purchase.state in ['cancel', 'draft']):
- return False
- return required
-
- @fields.depends('origin')
def on_change_with_company(self, name=None):
pool = Pool()
PurchaseLine = pool.get('purchase.line')
diff -r f936eb8c3c9c -r f160c38addd9 tests/scenario_analytic_purchase.rst
--- a/tests/scenario_analytic_purchase.rst Sat Jan 26 01:10:47 2019 +0100
+++ b/tests/scenario_analytic_purchase.rst Mon Feb 18 18:39:29 2019 +0100
@@ -60,12 +60,6 @@
>>> analytic_account = AnalyticAccount(root=root, parent=root,
... name='Analytic')
>>> analytic_account.save()
- >>> mandatory_root = AnalyticAccount(type='root', name='Root',
- ... mandatory=True)
- >>> mandatory_root.save()
- >>> mandatory_analytic_account = AnalyticAccount(root=mandatory_root,
- ... parent=mandatory_root, name='Mandatory Analytic')
- >>> mandatory_analytic_account.save()
Create parties::
@@ -111,25 +105,13 @@
>>> purchase.payment_term = payment_term
>>> purchase.invoice_method = 'order'
>>> purchase_line = purchase.lines.new()
- >>> entry, mandatory_entry = purchase_line.analytic_accounts
+ >>> entry, = purchase_line.analytic_accounts
>>> entry.root == root
True
- >>> bool(entry.required)
- False
>>> entry.account = analytic_account
- >>> mandatory_entry.root == mandatory_root
- True
- >>> bool(mandatory_entry.required)
- False
>>> purchase_line.product = product
>>> purchase_line.quantity = 5
- >>> mandatory_entry.account = mandatory_analytic_account
>>> purchase.click('quote')
- >>> purchase_line, = purchase.lines
- >>> mandatory_entry, = [a for a in purchase_line.analytic_accounts
- ... if a.root == mandatory_root]
- >>> bool(mandatory_entry.required)
- True
>>> purchase.click('confirm')
>>> purchase.click('process')
@@ -138,11 +120,9 @@
>>> Invoice = Model.get('account.invoice')
>>> invoice = Invoice(purchase.invoices[0].id)
>>> invoice_line, = invoice.lines
- >>> entry, mandatory_entry = invoice_line.analytic_accounts
+ >>> entry, = invoice_line.analytic_accounts
>>> entry.account == analytic_account
True
- >>> mandatory_entry.account == mandatory_analytic_account
- True
Purchase with an empty analytic account::
@@ -153,8 +133,7 @@
>>> purchase.payment_term = payment_term
>>> purchase.invoice_method = 'order'
>>> purchase_line = purchase.lines.new()
- >>> entry, mandatory_entry = purchase_line.analytic_accounts
- >>> mandatory_entry.account = mandatory_analytic_account
+ >>> entry, = purchase_line.analytic_accounts
>>> purchase_line.product = product
>>> purchase_line.quantity = 5
>>> purchase.click('quote')
@@ -166,26 +145,5 @@
>>> Invoice = Model.get('account.invoice')
>>> invoice = Invoice(purchase.invoices[0].id)
>>> invoice_line, = invoice.lines
- >>> entry, mandatory_entry = invoice_line.analytic_accounts
+ >>> entry, = invoice_line.analytic_accounts
>>> entry.account
- >>> mandatory_entry.account == mandatory_analytic_account
- True
-
-Analytic entries are not required until quotation::
-
- >>> purchase = Purchase()
- >>> purchase.party = supplier
- >>> purchase.payment_term = payment_term
- >>> purchase.invoice_method = 'order'
- >>> purchase_line = purchase.lines.new()
- >>> purchase_line.product = product
- >>> purchase_line.quantity = 5
- >>> purchase.save()
- >>> purchase.click('quote') # doctest: +IGNORE_EXCEPTION_DETAIL
- Traceback (most recent call last):
- ...
- PurchaseQuotationError: ...
- >>> purchase_line, = purchase.lines
- >>> entry, mandatory_entry = purchase_line.analytic_accounts
- >>> mandatory_entry.account = mandatory_analytic_account
- >>> purchase.click('quote')