summaryrefslogtreecommitdiff
path: root/addons/account
diff options
context:
space:
mode:
authorDenis Vermylen (dve) <dve@odoo.com>2016-08-04 14:20:12 +0200
committerThibault Delavallée <tde@openerp.com>2016-09-02 10:16:49 +0200
commitbc8d5dbf2c2ee19b337195bdb4bee8e6ba8508cf (patch)
treef108dbb28c9e94ee851e096d6b954c4ff3f30030 /addons/account
parent6a8e4c611918162e3d1673f86994a9aa1ce92372 (diff)
[REF] account: replace workflow by python code
Diffstat (limited to 'addons/account')
-rw-r--r--addons/account/__openerp__.py1
-rw-r--r--addons/account/demo/account_invoice_demo.yml13
-rw-r--r--addons/account/models/account_invoice.py59
-rw-r--r--addons/account/tests/test_account_customer_invoice.py4
-rw-r--r--addons/account/tests/test_account_supplier_invoice.py2
-rw-r--r--addons/account/tests/test_bank_statement_reconciliation.py2
-rw-r--r--addons/account/tests/test_payment.py2
-rw-r--r--addons/account/tests/test_reconciliation.py4
-rw-r--r--addons/account/views/account_invoice_view.xml18
-rw-r--r--addons/account/views/account_invoice_workflow.xml113
-rw-r--r--addons/account/views/account_unit_test.xml2
-rw-r--r--addons/account/wizard/account_invoice_refund.py2
-rw-r--r--addons/account/wizard/account_invoice_state.py4
13 files changed, 80 insertions, 146 deletions
diff --git a/addons/account/__openerp__.py b/addons/account/__openerp__.py
index 3be3a3bcccd..477655ac2b6 100644
--- a/addons/account/__openerp__.py
+++ b/addons/account/__openerp__.py
@@ -35,7 +35,6 @@ You could use this simplified accounting in case you work with an (external) acc
'views/account_end_fy.xml',
'views/account_invoice_view.xml',
'data/invoice_action_data.xml',
- 'views/account_invoice_workflow.xml',
'views/partner_view.xml',
'views/product_view.xml',
'views/account_analytic_view.xml',
diff --git a/addons/account/demo/account_invoice_demo.yml b/addons/account/demo/account_invoice_demo.yml
index 52f16f3240d..a925aefa6dd 100644
--- a/addons/account/demo/account_invoice_demo.yml
+++ b/addons/account/demo/account_invoice_demo.yml
@@ -17,7 +17,8 @@
price_unit: 280.0
quantity: 5.0
-
- !workflow {model: account.invoice, action: invoice_open, ref: demo_invoice_1}
+ !python {model: account.invoice, id: demo_invoice_1}:
+ self.action_invoice_open()
-
!record {model: account.invoice, id: demo_invoice_2}:
company_id: base.main_company
@@ -32,7 +33,8 @@
price_unit: 25
quantity: 20
-
- !workflow {model: account.invoice, action: invoice_open, ref: demo_invoice_2}
+ !python {model: account.invoice, id: demo_invoice_2}:
+ self.action_invoice_open()
-
!record {model: account.invoice, id: demo_invoice_3}:
company_id: base.main_company
@@ -47,7 +49,8 @@
price_unit: 15.0
quantity: 5.0
-
- !workflow {model: account.invoice, action: invoice_open, ref: demo_invoice_3}
+ !python {model: account.invoice, id: demo_invoice_3}:
+ self.action_invoice_open()
-
Set the context for supplier bills because the 'type' field is readonly in invoice form views, so it value won't be considered by the yaml import
-
@@ -90,7 +93,7 @@
if account:
line_vals['account_id'] = account.id
self._update('account.invoice.line', 'account', line_vals, 'ceo_wages_line')
- self.env['account.invoice'].browse(ref('demo_invoice_january_wages')).signal_workflow('invoice_open')
+ self.env['account.invoice'].browse(ref('demo_invoice_january_wages')).action_invoice_open()
-
!record {model: account.invoice, id: demo_invoice_equipment_purchase}:
company_id: base.main_company
@@ -114,7 +117,7 @@
line_vals['invoice_line_tax_ids'] = [(6, 0, [tax_id])]
self._update('account.invoice.line', 'account', line_vals, 'coffee_machine_line')
self.env['account.invoice'].browse(ref('demo_invoice_equipment_purchase'))._onchange_invoice_line_ids()
- self.env['account.invoice'].browse(ref('demo_invoice_equipment_purchase')).signal_workflow('invoice_open')
+ self.env['account.invoice'].browse(ref('demo_invoice_equipment_purchase')).action_invoice_open()
-
!python {model: account.bank.statement.line, id: False} : |
account = self.env['account.account'].search([
diff --git a/addons/account/models/account_invoice.py b/addons/account/models/account_invoice.py
index 87be174486f..bf4604cd21a 100644
--- a/addons/account/models/account_invoice.py
+++ b/addons/account/models/account_invoice.py
@@ -345,6 +345,17 @@ class AccountInvoice(models.Model):
return invoice
+ @api.multi
+ def _write(self, vals):
+ pre_not_reconciled = self.filtered(lambda invoice: not invoice.reconciled)
+ pre_reconciled = self - pre_not_reconciled
+ res = super(AccountInvoice, self)._write(vals)
+ reconciled = self.filtered(lambda invoice: invoice.reconciled)
+ not_reconciled = self - reconciled
+ (reconciled & pre_reconciled).filtered(lambda invoice: invoice.state == 'open').action_invoice_paid()
+ (not_reconciled & pre_not_reconciled).filtered(lambda invoice: invoice.state == 'paid').action_invoice_cancel()
+ return res
+
@api.model
def fields_view_get(self, view_id=None, view_type=False, toolbar=False, submenu=False):
def get_view_id(xid, name):
@@ -428,10 +439,6 @@ class AccountInvoice(models.Model):
return self.with_context(ctx).write({'invoice_line_ids': []})
@api.multi
- def confirm_paid(self):
- return self.write({'state': 'paid'})
-
- @api.multi
def unlink(self):
for invoice in self:
if invoice.state not in ('draft', 'cancel'):
@@ -517,11 +524,11 @@ class AccountInvoice(models.Model):
self.date_due = max(line[0] for line in pterm_list)
@api.multi
- def action_cancel_draft(self):
+ def action_invoice_draft(self):
+ if self.filtered(lambda inv: inv.state != 'cancel'):
+ raise UserError(_("Invoice must be cancelled in order to reset it to draft."))
# go from canceled state to draft state
self.write({'state': 'draft', 'date': False})
- self.delete_workflow()
- self.create_workflow()
# Delete former printed invoice
try:
report_invoice = self.env['report']._get_report_from_name('account.report_invoice')
@@ -537,6 +544,44 @@ class AccountInvoice(models.Model):
return True
@api.multi
+ def action_invoice_proforma2(self):
+ if self.filtered(lambda inv: inv.state != 'draft'):
+ raise UserError(_("Invoice must be a draft in order to set it to Pro-forma."))
+ return self.write({'state': 'proforma2'})
+
+ @api.multi
+ def action_invoice_open(self):
+ # lots of duplicate calls to action_invoice_open, so we remove those already open
+ to_open_invoices = self.filtered(lambda inv: inv.state != 'open')
+ if to_open_invoices.filtered(lambda inv: inv.state not in ['proforma2', 'draft']):
+ raise UserError(_("Invoice must be in draft or Pro-forma state in order to validate it."))
+ to_open_invoices.action_date_assign()
+ to_open_invoices.action_move_create()
+ return to_open_invoices.invoice_validate()
+
+ @api.multi
+ def action_invoice_paid(self):
+ # lots of duplicate calls to action_invoice_paid, so we remove those already paid
+ to_pay_invoices = self.filtered(lambda inv: inv.state != 'paid')
+ if to_pay_invoices.filtered(lambda inv: inv.state != 'open'):
+ raise UserError(_('Invoice must be validated in order to set it to register payemnt.'))
+ if to_pay_invoices.filtered(lambda inv: not inv.reconciled):
+ raise UserError(_('You cannot pay an invoice which is partially paid. You need to reconcile payment entries first.'))
+ return to_pay_invoices.write({'state': 'paid'})
+
+ @api.multi
+ def action_invoice_re_open(self):
+ if self.filtered(lambda inv: inv.state != 'paid'):
+ raise UserError(_('Invoice must be paid in order to set it to register payemnt.'))
+ return self.write({'state': 'open'})
+
+ @api.multi
+ def action_invoice_cancel(self):
+ if self.filtered(lambda inv: inv.state not in ['proforma2', 'draft', 'open']):
+ raise UserError(_("Invoice must be in draft or Pro-forma state in order to validate it."))
+ return self.action_cancel()
+
+ @api.multi
def get_formview_id(self):
""" Update form view id of action to open the invoice """
if self.type in ('in_invoice', 'in_refund'):
diff --git a/addons/account/tests/test_account_customer_invoice.py b/addons/account/tests/test_account_customer_invoice.py
index f24b9460cc8..0c559892644 100644
--- a/addons/account/tests/test_account_customer_invoice.py
+++ b/addons/account/tests/test_account_customer_invoice.py
@@ -71,7 +71,7 @@ class TestAccountCustomerInvoice(AccountTestUsers):
self.assertEquals(self.account_invoice_customer0.state, 'draft')
# I change the state of invoice to "Proforma2" by clicking PRO-FORMA button
- self.account_invoice_customer0.signal_workflow('invoice_proforma2')
+ self.account_invoice_customer0.action_invoice_proforma2()
# I check that the invoice state is now "Proforma2"
self.assertEquals(self.account_invoice_customer0.state, 'proforma2')
@@ -80,7 +80,7 @@ class TestAccountCustomerInvoice(AccountTestUsers):
self.assertEquals(len(self.account_invoice_customer0.move_id), 0)
# I validate invoice by creating on
- self.account_invoice_customer0.signal_workflow('invoice_open')
+ self.account_invoice_customer0.action_invoice_open()
# I check that the invoice state is "Open"
self.assertEquals(self.account_invoice_customer0.state, 'open')
diff --git a/addons/account/tests/test_account_supplier_invoice.py b/addons/account/tests/test_account_supplier_invoice.py
index 81a2517f2db..671cfb2dcb0 100644
--- a/addons/account/tests/test_account_supplier_invoice.py
+++ b/addons/account/tests/test_account_supplier_invoice.py
@@ -36,7 +36,7 @@ class TestAccountSupplierInvoice(AccountingTestCase):
self.assertTrue((invoice.state == 'draft'), "Initially vendor bill state is Draft")
#change the state of invoice to open by clicking Validate button
- invoice.signal_workflow('invoice_open')
+ invoice.action_invoice_open()
#I cancel the account move which is in posted state and verifies that it gives warning message
with self.assertRaises(Warning):
diff --git a/addons/account/tests/test_bank_statement_reconciliation.py b/addons/account/tests/test_bank_statement_reconciliation.py
index 56f38fa3e69..0aee2f90811 100644
--- a/addons/account/tests/test_bank_statement_reconciliation.py
+++ b/addons/account/tests/test_bank_statement_reconciliation.py
@@ -66,7 +66,7 @@ class TestBankStatementReconciliation(AccountingTestCase):
'name': '.',
'account_id': self.env['account.account'].search([('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
})
- invoice.signal_workflow('invoice_open')
+ invoice.action_invoice_open()
mv_line = None
for l in invoice.move_id.line_ids:
diff --git a/addons/account/tests/test_payment.py b/addons/account/tests/test_payment.py
index 374ceb9c5f3..d593f4fd8e8 100644
--- a/addons/account/tests/test_payment.py
+++ b/addons/account/tests/test_payment.py
@@ -55,7 +55,7 @@ class TestPayment(AccountingTestCase):
'name': 'something',
'account_id': self.account_revenue.id,
})
- invoice.signal_workflow('invoice_open')
+ invoice.action_invoice_open()
return invoice
def reconcile(self, liquidity_aml, amount=0.0, amount_currency=0.0, currency_id=None):
diff --git a/addons/account/tests/test_reconciliation.py b/addons/account/tests/test_reconciliation.py
index ee31cf4a853..d957f7c9f5a 100644
--- a/addons/account/tests/test_reconciliation.py
+++ b/addons/account/tests/test_reconciliation.py
@@ -56,7 +56,7 @@ class TestReconciliation(AccountingTestCase):
})
#validate invoice
- invoice.signal_workflow('invoice_open')
+ invoice.action_invoice_open()
return invoice
def make_payment(self, invoice_record, bank_journal, amount=0.0, amount_currency=0.0, currency_id=None):
@@ -283,7 +283,7 @@ class TestReconciliation(AccountingTestCase):
})
]
})
- invoice.signal_workflow('invoice_open')
+ invoice.action_invoice_open()
# We create a bank statement with two lines of 1.00 USD each.
statement = self.acc_bank_stmt_model.create({
'journal_id': self.bank_journal_usd_id,
diff --git a/addons/account/views/account_invoice_view.xml b/addons/account/views/account_invoice_view.xml
index cfb13ee4ac4..c10018794ea 100644
--- a/addons/account/views/account_invoice_view.xml
+++ b/addons/account/views/account_invoice_view.xml
@@ -217,11 +217,11 @@
<field name="arch" type="xml">
<form string="Vendor Bill">
<header>
- <button name="invoice_open" states="draft,proforma2" string="Validate" class="oe_highlight" groups="account.group_account_invoice"/>
+ <button name="action_invoice_open" type="object" states="draft,proforma2" string="Validate" class="oe_highlight" groups="account.group_account_invoice"/>
<button name="%(action_account_invoice_payment)d" type="action" states="open" string="Register Payment" groups="account.group_account_invoice" class="oe_highlight"/>
<button name="%(action_account_invoice_refund)d" type='action' string='Ask Refund' groups="account.group_account_invoice" attrs="{'invisible': ['|',('type', '=', 'in_refund'),('state','not in',('open','paid'))]}"/>
- <button name="invoice_cancel" states="draft,proforma2" string="Cancel Bill" groups="account.group_account_invoice"/>
- <button name="action_cancel_draft" states="cancel" string="Set to Draft" type="object" groups="account.group_account_invoice"/>
+ <button name="action_invoice_cancel" type="object" states="draft,proforma2" string="Cancel Bill" groups="account.group_account_invoice"/>
+ <button name="action_invoice_draft" states="cancel" string="Set to Draft" type="object" groups="account.group_account_invoice"/>
<field name="state" widget="statusbar" statusbar_visible="draft,open,paid" />
</header>
<div class="alert alert-info" role="alert" style="margin-bottom:0px;" attrs="{'invisible': [('has_outstanding','=',False)]}">
@@ -352,12 +352,12 @@
<button name="action_invoice_sent" type="object" string="Send by Email" attrs="{'invisible':['|',('sent','=',False), ('state', '!=', 'open')]}" groups="base.group_user"/>
<button name="invoice_print" string="Print Invoice" type="object" attrs="{'invisible':['|',('sent','=',False), ('state', '!=', 'open')]}" groups="base.group_user"/>
<button name="%(action_account_invoice_payment)d" type="action" states="open" string="Register Payment" groups="account.group_account_invoice" class="oe_highlight"/>
- <button name="invoice_open" states="draft" string="Validate" class="oe_highlight" groups="account.group_account_user"/>
- <button name="invoice_open" states="proforma2" string="Validate" groups="account.group_account_user"/>
- <button name="invoice_proforma2" states="draft" string="PRO-FORMA" groups="account.group_proforma_invoices"/>
- <button name="%(action_account_invoice_refund)d" type='action' string='Refund Invoice' groups="account.group_account_user" attrs="{'invisible': ['|',('type', '=', 'out_refund'), ('state', 'not in', ('open','proforma2','paid'))]}"/>
- <button name="invoice_cancel" states="draft,proforma2,open" string="Cancel Invoice" groups="base.group_no_one"/>
- <button name="action_cancel_draft" states="cancel" string="Reset to Draft" type="object" groups="account.group_account_user"/>
+ <button name="action_invoice_open" type="object" states="draft" string="Validate" class="oe_highlight" groups="base.group_account_user"/>
+ <button name="action_invoice_open" type="object" states="proforma2" string="Validate" groups="base.group_account_user"/>
+ <button name="action_invoice_proforma2" type="object" states="draft" string="PRO-FORMA" groups="account.group_proforma_invoices"/>
+ <button name="%(action_account_invoice_refund)d" type='action' string='Refund Invoice' groups="base.group_account_user" attrs="{'invisible': ['|',('type', '=', 'out_refund'), ('state', 'not in', ('open','proforma2','paid'))]}"/>
+ <button name="action_invoice_cancel" type="object" states="draft,proforma2,open" string="Cancel Invoice" groups="base.group_no_one"/>
+ <button name="action_invoice_draft" states="cancel" string="Reset to Draft" type="object" groups="base.group_account_user"/>
<field name="state" widget="statusbar" nolabel="1" statusbar_visible="draft,open,paid"/>
</header>
<div class="alert alert-info" role="alert" style="margin-bottom:0px;" attrs="{'invisible': [('has_outstanding','=',False)]}">
diff --git a/addons/account/views/account_invoice_workflow.xml b/addons/account/views/account_invoice_workflow.xml
deleted file mode 100644
index b5e5e3a1948..00000000000
--- a/addons/account/views/account_invoice_workflow.xml
+++ /dev/null
@@ -1,113 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<odoo>
- <data>
-
- <record id="wkf" model="workflow">
- <field name="name">account.invoice.basic</field>
- <field name="osv">account.invoice</field>
- <field name="on_create">True</field>
- </record>
-
- <record id="act_draft" model="workflow.activity">
- <field name="wkf_id" ref="wkf"/>
- <field name="flow_start">True</field>
- <field name="name">draft</field>
- </record>
- <record id="act_proforma2" model="workflow.activity">
- <field name="wkf_id" ref="wkf"/>
- <field name="name">proforma2</field>
- <field name="action">write({'state':'proforma2'})</field>
- <field name="kind">function</field>
- </record>
- <record id="act_open" model="workflow.activity">
- <field name="wkf_id" ref="wkf"/>
- <field name="name">open</field>
- <field name="action">action_date_assign()
-action_move_create()
-invoice_validate()</field>
- <field name="kind">function</field>
- </record>
- <record model="workflow.activity" id="act_open_test">
- <field name="wkf_id" ref="wkf"/>
- <field name="name">re-open</field>
- <field name="action">write({'state':'open'})</field>
- <field name="kind">function</field>
- </record>
- <record id="act_paid" model="workflow.activity">
- <field name="wkf_id" ref="wkf"/>
- <field name="name">paid</field>
- <!--<field name="flow_stop">True</field>-->
- <field name="action">confirm_paid()</field>
- <field name="kind">function</field>
- <field name="signal_send">subflow.paid</field>
- </record>
- <record id="act_cancel" model="workflow.activity">
- <field name="wkf_id" ref="wkf"/>
- <field name="name">cancel</field>
- <field name="flow_stop">True</field>
- <field name="action">action_cancel()
-write({'state':'cancel'})</field>
- <field name="kind">function</field>
- </record>
-
- <record id="t4" model="workflow.transition">
- <field name="act_from" ref="act_draft"/>
- <field name="act_to" ref="act_open"/>
- <field name="signal">invoice_open</field>
- </record>
- <record id="t8" model="workflow.transition">
- <field name="act_from" ref="act_open"/>
- <field name="act_to" ref="act_paid"/>
- <field name="trigger_model"/>
- <field name="trigger_expr_id"/>
- <field name="condition">reconciled</field>
- </record>
- <record id="t9" model="workflow.transition">
- <field name="act_from" ref="act_draft"/>
- <field name="act_to" ref="act_cancel"/>
- <field name="signal">invoice_cancel</field>
- </record>
- <record id="t12" model="workflow.transition">
- <field name="act_from" ref="act_open"/>
- <field name="act_to" ref="act_cancel"/>
- <field name="signal">invoice_cancel</field>
- </record>
- <record id="t13" model="workflow.transition">
- <field name="act_from" ref="act_paid"/>
- <field name="act_to" ref="act_open_test"/>
- <field name="signal"/>
- <field name="condition">not reconciled</field>
- </record>
- <record id="t14" model="workflow.transition">
- <field name="act_from" ref="act_open_test"/>
- <field name="act_to" ref="act_cancel"/>
- <field name="signal">invoice_cancel</field>
- </record>
-
- <record id="open_test_to_paid" model="workflow.transition">
- <field name="act_from" ref="act_open_test"/>
- <field name="act_to" ref="act_paid"/>
- <field name="trigger_model"/>
- <field name="trigger_expr_id"/>
- <field name="condition">reconciled</field>
- </record>
-
- <record id="draft_to_pro2" model="workflow.transition">
- <field name="act_from" ref="account.act_draft"/>
- <field name="act_to" ref="act_proforma2"/>
- <field name="signal">invoice_proforma2</field>
- </record>
-
- <record id="pro2_to_open" model="workflow.transition">
- <field name="act_from" ref="act_proforma2"/>
- <field name="act_to" ref="account.act_open"/>
- <field name="signal">invoice_open</field>
- </record>
-
- <record id="pro2_to_cancel" model="workflow.transition">
- <field name="act_from" ref="act_proforma2"/>
- <field name="act_to" ref="account.act_cancel"/>
- <field name="signal">invoice_cancel</field>
- </record>
- </data>
-</odoo>
diff --git a/addons/account/views/account_unit_test.xml b/addons/account/views/account_unit_test.xml
index 3991ce9ffcc..5a176e58ceb 100644
--- a/addons/account/views/account_unit_test.xml
+++ b/addons/account/views/account_unit_test.xml
@@ -44,7 +44,7 @@
<test expr="sum([l.price_subtotal for l in invoice_line_ids]) == amount_untaxed"/>
</assert>
- <workflow action="invoice_open" model="account.invoice" ref="test_invoice_1"/>
+ <function model="account.invoice" name="action_invoice_open" eval="[[ref('test_invoice_1')]]"/>
<assert id="test_invoice_1" model="account.invoice" string="Test invoice 1 is now open">
<test expr="state">open</test>
diff --git a/addons/account/wizard/account_invoice_refund.py b/addons/account/wizard/account_invoice_refund.py
index 031999d8042..a2b6a240ad9 100644
--- a/addons/account/wizard/account_invoice_refund.py
+++ b/addons/account/wizard/account_invoice_refund.py
@@ -71,7 +71,7 @@ class AccountInvoiceRefund(models.TransientModel):
to_reconcile_ids.setdefault(line.account_id.id, []).append(line.id)
if line.reconciled:
line.remove_move_reconcile()
- refund.signal_workflow('invoice_open')
+ refund.action_invoice_open()
for tmpline in refund.move_id.line_ids:
if tmpline.account_id.id == inv.account_id.id:
to_reconcile_lines += tmpline
diff --git a/addons/account/wizard/account_invoice_state.py b/addons/account/wizard/account_invoice_state.py
index e631bab8348..025df465a57 100644
--- a/addons/account/wizard/account_invoice_state.py
+++ b/addons/account/wizard/account_invoice_state.py
@@ -19,7 +19,7 @@ class AccountInvoiceConfirm(models.TransientModel):
for record in self.env['account.invoice'].browse(active_ids):
if record.state not in ('draft', 'proforma', 'proforma2'):
raise UserError(_("Selected invoice(s) cannot be confirmed as they are not in 'Draft' or 'Pro-Forma' state."))
- record.signal_workflow('invoice_open')
+ record.action_invoice_open()
return {'type': 'ir.actions.act_window_close'}
@@ -40,5 +40,5 @@ class AccountInvoiceCancel(models.TransientModel):
for record in self.env['account.invoice'].browse(active_ids):
if record.state in ('cancel', 'paid'):
raise UserError(_("Selected invoice(s) cannot be cancelled as they are already in 'Cancelled' or 'Done' state."))
- record.signal_workflow('invoice_cancel')
+ record.action_invoice_cancel()
return {'type': 'ir.actions.act_window_close'}