[IMP] account: update account.invoice.send
Due to new composer, it is a bit less necessary to create them on the fly randomly. Some quick code cleaning is performed to better understand code and variables. Notably 'default_get' override was a bit messy and should not return unwanted values. Task-3093257 (Mail: The Composer Update) Task-3149286 (Account: Cleanup account.invoice.send wizard) Part-of: odoo/odoo#107356
This commit is contained in:
@@ -31,23 +31,23 @@ class AccountInvoiceSend(models.TransientModel):
|
||||
readonly=True)
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
res = super(AccountInvoiceSend, self).default_get(fields)
|
||||
res_ids = self._context.get('active_ids')
|
||||
def default_get(self, fields_list):
|
||||
result = super().default_get(fields_list)
|
||||
res_ids = self.env.context.get('active_ids')
|
||||
|
||||
invoices = self.env['account.move'].browse(res_ids).filtered(lambda move: move.is_invoice(include_receipts=True))
|
||||
if not invoices:
|
||||
raise UserError(_("You can only send invoices."))
|
||||
|
||||
composer = self.env['mail.compose.message'].create({
|
||||
'composition_mode': 'comment' if len(res_ids) == 1 else 'mass_mail',
|
||||
'subtype_id': self.env['ir.model.data']._xmlid_to_res_id('mail.mt_comment'),
|
||||
})
|
||||
res.update({
|
||||
'invoice_ids': res_ids,
|
||||
'composer_id': composer.id,
|
||||
})
|
||||
return res
|
||||
if 'invoice_ids' in fields_list and not result.get('invoice_ids'):
|
||||
result['invoice_ids'] = res_ids
|
||||
if 'composer_id' in fields_list and not result.get('composer_id'):
|
||||
composer = self.env['mail.compose.message'].create({
|
||||
'composition_mode': 'comment' if len(res_ids) == 1 else 'mass_mail',
|
||||
'subtype_id': self.env['ir.model.data']._xmlid_to_res_id('mail.mt_comment'),
|
||||
})
|
||||
result['composer_id'] = composer.id
|
||||
return result
|
||||
|
||||
@api.onchange('invoice_ids')
|
||||
def _compute_composition_mode(self):
|
||||
|
||||
@@ -14,10 +14,17 @@
|
||||
<field name="move_types"/>
|
||||
</div>
|
||||
<!-- truly invisible fields for control and options -->
|
||||
<field name="author_id" invisible="1"/>
|
||||
<field name="composition_mode" invisible="1"/>
|
||||
<field name="invoice_ids" invisible="1"/>
|
||||
<field name="email_from" invisible="1" />
|
||||
<field name="invoice_ids" invisible="1"/>
|
||||
<field name="lang" invisible="1"/>
|
||||
<field name="mail_server_id" invisible="1"/>
|
||||
<field name="model" invisible="1"/>
|
||||
<field name="render_model" invisible="1"/>
|
||||
<field name="res_ids" invisible="1"/>
|
||||
<field name="subtype_id" invisible="1"/>
|
||||
|
||||
<div name="option_print">
|
||||
<field name="is_print" />
|
||||
<b><label for="is_print"/></b>
|
||||
|
||||
@@ -61,7 +61,7 @@ class BaseMailAccountPerformance(AccountTestInvoicingCommon, MailCommon):
|
||||
])
|
||||
],
|
||||
'login': 'user_account',
|
||||
'name': 'Ernest Employee',
|
||||
'name': 'Ernest Employee Account',
|
||||
'notification_type': 'inbox',
|
||||
'signature': '--\nErnest',
|
||||
})
|
||||
@@ -77,7 +77,7 @@ class BaseMailAccountPerformance(AccountTestInvoicingCommon, MailCommon):
|
||||
])
|
||||
],
|
||||
'login': 'user_account_other',
|
||||
'name': 'Eglantine Employee',
|
||||
'name': 'Eglantine Employee AccountOther',
|
||||
'notification_type': 'inbox',
|
||||
'signature': '--\nEglantine',
|
||||
})
|
||||
@@ -134,6 +134,19 @@ class BaseMailAccountPerformance(AccountTestInvoicingCommon, MailCommon):
|
||||
class TestAccountComposerPerformance(BaseMailAccountPerformance):
|
||||
""" Test performance of custom composer for moves. """
|
||||
|
||||
def test_assert_initial_values(self):
|
||||
""" Test initial values to ease understanding of results and notifications """
|
||||
for move in self.test_account_moves:
|
||||
with self.subTest(move=move):
|
||||
self.assertEqual(
|
||||
move.invoice_user_id,
|
||||
self.user_account_other,
|
||||
)
|
||||
self.assertEqual(
|
||||
move.message_partner_ids,
|
||||
self.user_accountman.partner_id,
|
||||
)
|
||||
|
||||
@users('user_account')
|
||||
@warmup
|
||||
@mute_logger('odoo.addons.mail.models.mail_mail', 'odoo.models.unlink')
|
||||
|
||||
Reference in New Issue
Block a user