[FIX] save wizard before run

we must save 'account.invoice.line.update' to be able match them to real invoice lines,
This commit is contained in:
Iryna Vyshnevska
2019-08-13 12:40:28 +03:00
parent 5b620a6c5f
commit beb0a27ad6
7 changed files with 37 additions and 24 deletions

View File

@@ -1 +1,2 @@
from . import models
from . import wizard

View File

@@ -12,7 +12,7 @@
'author': 'Akretion',
'website': 'https://github.com/akretion/odoo-usability',
'depends': [
'account'
'account',
],
'data': [
'wizard/account_invoice_update_view.xml',

View File

@@ -0,0 +1 @@
from . import account_invoice

View File

@@ -0,0 +1,22 @@
# Copyright 2019 Camptocamp
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api, _
from odoo.exceptions import UserError
import odoo.addons.decimal_precision as dp
class AccountInvoice(models.Model):
_inherit = 'account.invoice'
def prepare_update_wizard(self):
self.ensure_one()
wizard = self.env['account.invoice.update']
res = wizard._prepare_default_get(self)
action = self.env.ref(
'account_invoice_update_wizard.account_invoice_update_action'
).read()[0]
action['name'] = "Update Wizard"
action['res_id'] = wizard.create(res).id
return action

View File

@@ -43,11 +43,9 @@ class TestAccountInvoiceUpdateWizard(SavepointCase):
'name': '',
})
def create_wizard(self):
UpdateWizard = self.env['account.invoice.update'].with_context(
active_model='account.invoice',
active_id=self.invoice1.id)
self.wiz = UpdateWizard.create({})
def create_wizard(self, invoice):
res = self.invoice1.prepare_update_wizard()
self.wiz = self.env['account.invoice.update'].browse(res['res_id'])
def test_add_analytic_account_line1(self):
""" Add analytic account on an invoice line
@@ -58,7 +56,7 @@ class TestAccountInvoiceUpdateWizard(SavepointCase):
- create a new analytic line.
"""
self.invoice1.action_invoice_open()
self.create_wizard()
self.create_wizard(self.invoice1)
wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
@@ -80,7 +78,7 @@ class TestAccountInvoiceUpdateWizard(SavepointCase):
self.inv_line1.account_analytic_id = self.aa2
self.invoice1.action_invoice_open()
self.create_wizard()
self.create_wizard(self.invoice1)
wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
@@ -105,7 +103,7 @@ class TestAccountInvoiceUpdateWizard(SavepointCase):
self.inv_line2.unit_price = 42.0
self.invoice1.action_invoice_open()
self.create_wizard()
self.create_wizard(self.invoice1)
line1 = self.wiz.line_ids[0]
line1.account_analytic_id = self.aa1
@@ -119,7 +117,7 @@ class TestAccountInvoiceUpdateWizard(SavepointCase):
This will update move line.
"""
self.invoice1.action_invoice_open()
self.create_wizard()
self.create_wizard(self.invoice1)
wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
@@ -141,7 +139,7 @@ class TestAccountInvoiceUpdateWizard(SavepointCase):
self.inv_line1.analytic_tag_ids = self.atag1
self.invoice1.action_invoice_open()
self.create_wizard()
self.create_wizard(self.invoice1)
wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
@@ -162,7 +160,7 @@ class TestAccountInvoiceUpdateWizard(SavepointCase):
- create an analytic line
"""
self.invoice1.action_invoice_open()
self.create_wizard()
self.create_wizard(self.invoice1)
wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)
@@ -186,7 +184,7 @@ class TestAccountInvoiceUpdateWizard(SavepointCase):
self.inv_line1.account_analytic_id = self.aa2
self.invoice1.action_invoice_open()
self.create_wizard()
self.create_wizard(self.invoice1)
wiz_line = self.wiz.line_ids.filtered(
lambda rec: rec.invoice_line_id == self.inv_line1)

View File

@@ -11,7 +11,7 @@
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="arch" type="xml">
<button name="action_invoice_draft" position="before">
<button name="%(account_invoice_update_action)d" type="action" string="Update Invoice" states="open,paid" groups="account.group_account_invoice"/>
<button name="prepare_update_wizard" type="object" string="Update Invoice" states="open,paid" groups="account.group_account_invoice"/>
</button>
</field>
</record>
@@ -21,7 +21,7 @@
<field name="inherit_id" ref="account.invoice_form"/>
<field name="arch" type="xml">
<button name="action_invoice_draft" position="before">
<button name="%(account_invoice_update_action)d" type="action" string="Update Invoice" states="open,paid" groups="account.group_account_invoice"/>
<button name="prepare_update_wizard" type="object" string="Update Invoice" states="open,paid" groups="account.group_account_invoice"/>
</button>
</field>
</record>

View File

@@ -60,15 +60,6 @@ class AccountInvoiceUpdate(models.TransientModel):
}])
return res
@api.model
def default_get(self, fields_list):
res = super(AccountInvoiceUpdate, self).default_get(fields_list)
assert self._context.get('active_model') == 'account.invoice',\
'active_model should be account.invoice'
inv = self.env['account.invoice'].browse(self._context['active_id'])
res = self._prepare_default_get(inv)
return res
@api.onchange('type')
def type_on_change(self):
res = {'domain': {}}