mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
[MIG] account_invoice_change: migrate to 13.0
H4386
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
'name': 'Account Invoice Change',
|
'name': 'Account Invoice Change',
|
||||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||||
'version': '12.0.1.0.0',
|
'version': '13.0.1.0.0',
|
||||||
'category': 'Accounting',
|
'category': 'Accounting',
|
||||||
'sequence': 95,
|
'sequence': 95,
|
||||||
'summary': 'Technical foundation for changing invoices.',
|
'summary': 'Technical foundation for changing invoices.',
|
||||||
|
|||||||
@@ -1,60 +1,51 @@
|
|||||||
from odoo.addons.account.tests.account_test_users import AccountTestUsers
|
from odoo.addons.account.tests.account_test_users import AccountTestUsers
|
||||||
from odoo import fields
|
from odoo import fields
|
||||||
|
|
||||||
|
|
||||||
class TestInvoiceChange(AccountTestUsers):
|
class TestInvoiceChange(AccountTestUsers):
|
||||||
|
|
||||||
def test_invoice_change_basic(self):
|
def test_invoice_change_basic(self):
|
||||||
self.account_invoice_obj = self.env['account.invoice']
|
self.account_invoice_obj = self.env['account.move']
|
||||||
self.payment_term = self.env.ref('account.account_payment_term_advance')
|
self.payment_term = self.env.ref('account.account_payment_term_advance')
|
||||||
self.journalrec = self.env['account.journal'].search([('type', '=', 'sale')])[0]
|
self.journalrec = self.env['account.journal'].search([('type', '=', 'sale')])[0]
|
||||||
self.partner3 = self.env.ref('base.res_partner_3')
|
self.partner3 = self.env.ref('base.res_partner_3')
|
||||||
account_user_type = self.env.ref('account.data_account_type_receivable')
|
self.invoice_basic = self.account_invoice_obj.with_user(self.account_user).create({
|
||||||
self.account_rec1_id = self.account_model.sudo(self.account_manager.id).create(dict(
|
'type': 'out_invoice',
|
||||||
code="cust_acc",
|
'name': "Test Customer Invoice",
|
||||||
name="customer account",
|
'invoice_payment_term_id': self.payment_term.id,
|
||||||
user_type_id=account_user_type.id,
|
'journal_id': self.journalrec.id,
|
||||||
reconcile=True,
|
'partner_id': self.partner3.id,
|
||||||
))
|
# account_id=self.account_rec1_id.id,
|
||||||
invoice_line_data = [
|
'line_ids': [(0, 0, {
|
||||||
(0, 0,
|
'product_id': self.env.ref('product.product_product_5').id,
|
||||||
{
|
'quantity': 10.0,
|
||||||
'product_id': self.env.ref('product.product_product_5').id,
|
'account_id': self.env['account.account'].search(
|
||||||
'quantity': 10.0,
|
[('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
|
||||||
'account_id': self.env['account.account'].search(
|
'name': 'product test 5',
|
||||||
[('user_type_id', '=', self.env.ref('account.data_account_type_revenue').id)], limit=1).id,
|
'price_unit': 100.00,
|
||||||
'name': 'product test 5',
|
})],
|
||||||
'price_unit': 100.00,
|
})
|
||||||
}
|
|
||||||
)
|
|
||||||
]
|
|
||||||
self.invoice_basic = self.account_invoice_obj.sudo(self.account_user.id).create(dict(
|
|
||||||
name="Test Customer Invoice",
|
|
||||||
reference_type="none",
|
|
||||||
payment_term_id=self.payment_term.id,
|
|
||||||
journal_id=self.journalrec.id,
|
|
||||||
partner_id=self.partner3.id,
|
|
||||||
account_id=self.account_rec1_id.id,
|
|
||||||
invoice_line_ids=invoice_line_data
|
|
||||||
))
|
|
||||||
self.assertEqual(self.invoice_basic.state, 'draft')
|
self.assertEqual(self.invoice_basic.state, 'draft')
|
||||||
self.invoice_basic.action_invoice_open()
|
self.invoice_basic.action_post()
|
||||||
self.assertEqual(self.invoice_basic.state, 'open')
|
self.assertEqual(self.invoice_basic.state, 'posted')
|
||||||
self.assertEqual(self.invoice_basic.date, fields.Date.today())
|
self.assertEqual(self.invoice_basic.date, fields.Date.today())
|
||||||
self.assertEqual(self.invoice_basic.user_id, self.account_user)
|
self.assertEqual(self.invoice_basic.invoice_date, fields.Date.today())
|
||||||
self.assertEqual(self.invoice_basic.move_id.date, fields.Date.today())
|
self.assertEqual(self.invoice_basic.invoice_user_id, self.account_user)
|
||||||
self.assertEqual(self.invoice_basic.move_id.line_ids[0].date, fields.Date.today())
|
self.assertEqual(self.invoice_basic.line_ids[0].date, fields.Date.today())
|
||||||
|
|
||||||
ctx = {'active_model': 'account.invoice', 'active_ids': [self.invoice_basic.id]}
|
ctx = {'active_model': 'account.move', 'active_ids': [self.invoice_basic.id]}
|
||||||
change = self.env['account.invoice.change'].with_context(ctx).create({})
|
change = self.env['account.invoice.change'].with_context(ctx).create({})
|
||||||
self.assertEqual(change.date, self.invoice_basic.date)
|
self.assertEqual(change.date, self.invoice_basic.date)
|
||||||
self.assertEqual(change.user_id, self.invoice_basic.user_id)
|
self.assertEqual(change.invoice_date, self.invoice_basic.invoice_date)
|
||||||
|
self.assertEqual(change.invoice_user_id, self.invoice_basic.invoice_user_id)
|
||||||
|
|
||||||
change_date = '2018-01-01'
|
change_date = '2018-01-01'
|
||||||
|
change_invoice_date = '2019-01-01'
|
||||||
change_user = self.env.user
|
change_user = self.env.user
|
||||||
change.write({'user_id': change_user.id, 'date': change_date})
|
change.write({'invoice_user_id': change_user.id, 'date': change_date, 'invoice_date': change_invoice_date})
|
||||||
|
|
||||||
change.affect_change()
|
change.affect_change()
|
||||||
self.assertEqual(self.invoice_basic.date, change_date)
|
self.assertEqual(str(self.invoice_basic.date), change_date)
|
||||||
self.assertEqual(self.invoice_basic.user_id, change_user)
|
self.assertEqual(str(self.invoice_basic.invoice_date), change_invoice_date)
|
||||||
self.assertEqual(self.invoice_basic.move_id.date, change_date)
|
self.assertEqual(self.invoice_basic.invoice_user_id, change_user)
|
||||||
self.assertEqual(self.invoice_basic.move_id.line_ids[0].date, change_date)
|
self.assertEqual(str(self.invoice_basic.line_ids[0].date), change_date)
|
||||||
|
|||||||
@@ -6,10 +6,11 @@ class InvoiceChangeWizard(models.TransientModel):
|
|||||||
_name = 'account.invoice.change'
|
_name = 'account.invoice.change'
|
||||||
_description = 'Invoice Change'
|
_description = 'Invoice Change'
|
||||||
|
|
||||||
invoice_id = fields.Many2one('account.invoice', string='Invoice', readonly=True, required=True)
|
move_id = fields.Many2one('account.move', string='Invoice', readonly=True, required=True)
|
||||||
invoice_company_id = fields.Many2one('res.company', readonly=True, related='invoice_id.company_id')
|
move_company_id = fields.Many2one('res.company', readonly=True, related='move_id.company_id')
|
||||||
user_id = fields.Many2one('res.users', string='Salesperson')
|
invoice_user_id = fields.Many2one('res.users', string='Salesperson')
|
||||||
date = fields.Date(string='Accounting Date')
|
date = fields.Date(string='Accounting Date')
|
||||||
|
invoice_date = fields.Date(string='Invoice Date')
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
def default_get(self, fields):
|
def default_get(self, fields):
|
||||||
@@ -22,35 +23,35 @@ class InvoiceChangeWizard(models.TransientModel):
|
|||||||
if not active_model or not active_ids:
|
if not active_model or not active_ids:
|
||||||
raise UserError(
|
raise UserError(
|
||||||
_("Programmation error: wizard action executed without active_model or active_ids in context."))
|
_("Programmation error: wizard action executed without active_model or active_ids in context."))
|
||||||
if active_model != 'account.invoice':
|
if active_model != 'account.move':
|
||||||
raise UserError(_(
|
raise UserError(_(
|
||||||
"Programmation error: the expected model for this action is 'account.invoice'. The provided one is '%d'.") % active_model)
|
"Programmation error: the expected model for this action is 'account.move'. The provided one is '%d'.") % active_model)
|
||||||
|
|
||||||
# Checks on received invoice records
|
# Checks on received invoice records
|
||||||
invoice = self.env[active_model].browse(active_ids)
|
invoice = self.env[active_model].browse(active_ids)
|
||||||
if len(invoice) != 1:
|
if len(invoice) != 1:
|
||||||
raise UserError(_("Invoice Change expects only one invoice."))
|
raise UserError(_("Invoice Change expects only one invoice."))
|
||||||
rec.update({
|
rec.update({
|
||||||
'invoice_id': invoice.id,
|
'move_id': invoice.id,
|
||||||
'user_id': invoice.user_id.id,
|
'invoice_user_id': invoice.invoice_user_id.id,
|
||||||
'date': invoice.date,
|
'date': invoice.date,
|
||||||
|
'invoice_date': invoice.invoice_date,
|
||||||
})
|
})
|
||||||
return rec
|
return rec
|
||||||
|
|
||||||
def _new_invoice_vals(self):
|
def _new_move_vals(self):
|
||||||
vals = {}
|
vals = {}
|
||||||
if self.invoice_id.user_id != self.user_id:
|
if self.move_id.invoice_user_id != self.invoice_user_id:
|
||||||
vals['user_id'] = self.user_id.id
|
vals['invoice_user_id'] = self.invoice_user_id.id
|
||||||
if self.invoice_id.date != self.date:
|
if self.move_id.date != self.date:
|
||||||
vals['date'] = self.date
|
vals['date'] = self.date
|
||||||
|
if self.move_id.invoice_date != self.invoice_date:
|
||||||
|
vals['invoice_date'] = self.invoice_date
|
||||||
return vals
|
return vals
|
||||||
|
|
||||||
@api.multi
|
|
||||||
def affect_change(self):
|
def affect_change(self):
|
||||||
self.ensure_one()
|
self.ensure_one()
|
||||||
vals = self._new_invoice_vals()
|
vals = self._new_move_vals()
|
||||||
if vals:
|
if vals:
|
||||||
self.invoice_id.write(vals)
|
self.move_id.write(vals)
|
||||||
if 'date' in vals and self.invoice_id.move_id:
|
|
||||||
self.invoice_id.move_id.write({'date': vals['date']})
|
|
||||||
return True
|
return True
|
||||||
|
|||||||
@@ -7,9 +7,10 @@
|
|||||||
<form string="Invoice Change">
|
<form string="Invoice Change">
|
||||||
<group>
|
<group>
|
||||||
<group name="group_left">
|
<group name="group_left">
|
||||||
<field name="invoice_id" invisible="1"/>
|
<field name="move_id" invisible="1"/>
|
||||||
<field name="invoice_company_id" invisible="1"/>
|
<field name="move_company_id" invisible="1"/>
|
||||||
<field name="user_id"/>
|
<field name="invoice_user_id"/>
|
||||||
|
<field name="invoice_date"/>
|
||||||
<field name="date"/>
|
<field name="date"/>
|
||||||
</group>
|
</group>
|
||||||
<group name="group_right"/>
|
<group name="group_right"/>
|
||||||
@@ -26,21 +27,20 @@
|
|||||||
<field name="name">Invoice Change Wizard</field>
|
<field name="name">Invoice Change Wizard</field>
|
||||||
<field name="type">ir.actions.act_window</field>
|
<field name="type">ir.actions.act_window</field>
|
||||||
<field name="res_model">account.invoice.change</field>
|
<field name="res_model">account.invoice.change</field>
|
||||||
<field name="view_type">form</field>
|
|
||||||
<field name="view_mode">form</field>
|
<field name="view_mode">form</field>
|
||||||
<field name="target">new</field>
|
<field name="target">new</field>
|
||||||
</record>
|
</record>
|
||||||
|
|
||||||
<record id="invoice_form_inherit" model="ir.ui.view">
|
<record id="view_move_form_inherit" model="ir.ui.view">
|
||||||
<field name="name">account.invoice.form.inherit</field>
|
<field name="name">account.move.form.inherit.invoice.change</field>
|
||||||
<field name="model">account.invoice</field>
|
<field name="model">account.move</field>
|
||||||
<field name="inherit_id" ref="account.invoice_form"/>
|
<field name="inherit_id" ref="account.view_move_form"/>
|
||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<xpath expr="//field[@name='state']" position="before">
|
<xpath expr="//field[@name='state']" position="before">
|
||||||
<button name="%(action_view_account_invoice_change)d" string="Change"
|
<button name="%(action_view_account_invoice_change)d" string="Change"
|
||||||
type="action" class="btn-secondary"
|
type="action" class="btn-secondary"
|
||||||
attrs="{'invisible': [('state', 'in', ('sale', 'done', 'cancel'))]}"
|
attrs="{'invisible': ['|', ('state', 'in', ('sale', 'done', 'cancel')), ('type', 'not in', ('out_invoice', 'out_refund'))]}"
|
||||||
context="{'default_invoice_id': id}"
|
context="{'default_move_id': id}"
|
||||||
groups="account.group_account_manager" />
|
groups="account.group_account_manager" />
|
||||||
</xpath>
|
</xpath>
|
||||||
</field>
|
</field>
|
||||||
|
|||||||
Reference in New Issue
Block a user