Skip to content

[IMP] account, sale, l10n_it_edi, l10n_tr_nilvera_einvoice: more visibility about the sent status of invoice #4811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 18.0-rd-accounting-onboarding-malb
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions addons/account/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,16 @@ def _sequence_year_range_monthly_regex(self):
tracking=True,
help="It indicates that the invoice/payment has been sent or the PDF has been generated.",
)

move_sent_state = fields.Selection(
selection=[('not_sent', "Not Sent"), ('sent', "Sent")],
default='not_sent',
tracking=True,
copy=False,
readonly=True,
help="It indicates that the invoice/payment has been sent or the PDF has been generated.",
)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the spec was not clear enough we actually don't want to get rid of is_move_sent but use it 👀 With the is_move_sent you can do compute on this field, it will reduce the diff a looot you will see ahah

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Creating a selection computed field that is set to sent when is_move_sent = True would make the is_move_sent column redundant. Therefore, we can remove it completely as there is no reason to keep it.


is_being_sent = fields.Boolean(
help="Is the move being sent asynchronously",
compute='_compute_is_being_sent'
Expand Down
2 changes: 1 addition & 1 deletion addons/account/models/account_move_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ def _link_invoice_documents(self, invoices_data):
if attachment := res_id_to_attachment.get(invoice.id):
invoice.message_main_attachment_id = attachment
invoice.invalidate_recordset(fnames=['invoice_pdf_report_id', 'invoice_pdf_report_file'])
invoice.is_move_sent = True
invoice.move_sent_state = 'sent'

@api.model
def _hook_if_errors(self, moves_data, allow_raising=True):
Expand Down
28 changes: 14 additions & 14 deletions addons/account/tests/test_account_move_send.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def test_move_composer_multi(self):
move_template = self.move_template.with_env(self.env)

for test_move in test_moves:
self.assertFalse(test_move.is_move_sent)
self.assertEqual(test_move.move_sent_state, 'not_sent')

with self.mock_mail_gateway(mail_unlink_sent=False):
self.env['account.move.send']._generate_and_send_invoices(
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_move_composer_multi(self):

# invoice update
for test_move in test_moves:
self.assertTrue(test_move.is_move_sent)
self.assertEqual(test_move.move_sent_state, 'sent')

@users('user_account')
@warmup
Expand Down Expand Up @@ -256,10 +256,10 @@ def test_move_composer_single(self):
'Should take invoice_user_id email')
self.assertEqual(print_msg.notified_partner_ids, test_customer + self.user_accountman.partner_id)
self.assertEqual(print_msg.subject, f'{self.env.user.company_id.name} Invoice (Ref {test_move.name})')
# tracking: is_move_sent
# tracking: move_sent_state
self.assertEqual(track_msg.author_id, self.env.user.partner_id)
self.assertEqual(track_msg.email_from, self.env.user.email_formatted)
self.assertTrue('is_move_sent' in track_msg.tracking_value_ids.field_id.mapped('name'))
self.assertTrue('move_sent_state' in track_msg.tracking_value_ids.field_id.mapped('name'))
# sent email
self.assertMailMail(
test_customer,
Expand Down Expand Up @@ -301,7 +301,7 @@ def test_move_composer_single(self):
self.assertEqual(composer.mail_template_id, move_template)

# invoice update
self.assertTrue(test_move.is_move_sent)
self.assertEqual(test_move.move_sent_state, 'sent')

@users('user_account')
@warmup
Expand Down Expand Up @@ -343,10 +343,10 @@ def test_move_composer_single_lang(self):
'Should take invoice_user_id email')
self.assertEqual(print_msg.notified_partner_ids, test_customer + self.user_accountman.partner_id)
self.assertEqual(print_msg.subject, f'SpanishSubject for {test_move.name}')
# tracking: is_move_sent
# tracking: move_sent_state
self.assertEqual(track_msg.author_id, self.env.user.partner_id)
self.assertEqual(track_msg.email_from, self.env.user.email_formatted)
self.assertTrue('is_move_sent' in track_msg.tracking_value_ids.field_id.mapped('name'))
self.assertTrue('move_sent_state' in track_msg.tracking_value_ids.field_id.mapped('name'))
# sent email
self.assertMailMail(
test_customer,
Expand Down Expand Up @@ -390,7 +390,7 @@ def test_move_composer_single_lang(self):
self.assertEqual(composer.mail_template_id, move_template)

# invoice update
self.assertTrue(test_move.is_move_sent)
self.assertEqual(test_move.move_sent_state, 'sent')

@users('user_account')
@warmup
Expand Down Expand Up @@ -1061,30 +1061,30 @@ def _hook_invoice_document_before_pdf_report_render(self, invoice, invoice_data)
self.assertEqual(payload_2['type'], 'warning')
self.assertEqual(sorted(payload_2['action_button']['res_ids']), invoices_error.ids)

def test_is_move_sent_state(self):
def test_move_sent_state(self):
# Post a move, nothing sent yet
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True)
self.assertFalse(invoice.is_move_sent)
self.assertEqual(invoice.move_sent_state, 'not_sent')
# Send via send & print
wizard = self.create_send_and_print(invoice)
wizard.action_send_and_print()
self.assertTrue(invoice.is_move_sent)
self.assertEqual(invoice.move_sent_state, 'sent')
# Revert move to draft
invoice.button_draft()
self.assertTrue(invoice.is_move_sent)
self.assertEqual(invoice.move_sent_state, 'sent')
# Unlink PDF
pdf_report = invoice.invoice_pdf_report_id
self.assertTrue(pdf_report)
invoice.invoice_pdf_report_id.unlink()
self.assertTrue(invoice.is_move_sent)
self.assertEqual(invoice.move_sent_state, 'sent')

def test_no_sending_method_selected(self):
invoice = self.init_invoice("out_invoice", amounts=[1000], post=True)
self.assertFalse(invoice.invoice_pdf_report_id)
wizard = self.create_send_and_print(invoice, sending_methods=[])
self.assertFalse(wizard.sending_methods)
wizard.action_send_and_print()
self.assertTrue(invoice.is_move_sent)
self.assertEqual(invoice.move_sent_state, 'sent')
self.assertTrue(invoice.invoice_pdf_report_id)

def test_get_sending_settings(self):
Expand Down
25 changes: 17 additions & 8 deletions addons/account/views/account_move_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,12 @@
invisible="payment_state == 'invoicing_legacy' or move_type == 'entry'"
optional="show"
/>
<field name="move_sent_state"
widget="badge"
string="Move Sent?"
decoration-info="move_sent_state == 'not_sent'"
decoration-success="move_sent_state == 'sent'"
optional="hide"/>
<field name="move_type" column_invisible="context.get('default_move_type', True)"/>
<field name="abnormal_amount_warning" column_invisible="1"/>
<field name="abnormal_date_warning" column_invisible="1"/>
Expand Down Expand Up @@ -922,7 +928,7 @@
<field name="show_reset_to_draft_button" invisible="1"/>

<field name="invoice_has_outstanding" invisible="1"/>
<field name="is_move_sent" invisible="1"/>
<field name="move_sent_state" invisible="1"/>
<field name="invoice_pdf_report_id" invisible="1"/>
<field name="need_cancel_request" invisible="1"/>
<field name="has_reconciled_entries" invisible="1"/>
Expand Down Expand Up @@ -1024,7 +1030,7 @@
context="{'default_partner_id': bank_partner_id, 'display_account_trust': True}"
domain="[('partner_id', '=', bank_partner_id)]"
invisible="move_type not in ('in_invoice', 'in_refund', 'in_receipt')"
readonly="is_move_sent and state != 'draft'"/>
readonly="move_sent_state == 'sent' and state != 'draft'"/>

<!-- Invoice payment terms (only invoices) + due date (only invoices / receipts) -->
<div class="o_td_label" invisible="move_type not in ('out_invoice', 'out_refund', 'in_invoice', 'in_refund', 'out_receipt', 'in_receipt')">
Expand Down Expand Up @@ -1403,7 +1409,7 @@
<field name="partner_bank_id"
context="{'default_partner_id': bank_partner_id, 'display_account_trust': True}"
domain="[('partner_id.ref_company_ids', 'parent_of', company_id)]"
readonly="is_move_sent and state != 'draft'"/>
readonly="move_sent_state == 'sent' and state != 'draft'"/>
<field name="payment_reference"
invisible="move_type not in ('out_invoice', 'out_refund')"
readonly="inalterable_hash"
Expand Down Expand Up @@ -1581,11 +1587,14 @@
<filter name="not_secured" string="Not Secured" domain="[('secured', '=', False), ('state', '=', 'posted')]"
groups="account.group_account_secured,base.group_no_one"/>
<separator/>
<filter name="not_sent"
string="Not Sent"
domain="[('is_move_sent', '=', False)]"
invisible="context.get('default_move_type') in ('in_invoice', 'in_refund', 'in_receipt')"
/>
<filter string="Sent invoices"
name="sent_invoices"
domain="[('move_sent_state', '=', 'sent')]"
invisible="context.get('default_move_type') in ('in_invoice', 'in_refund', 'in_receipt')"/>
<filter string="Not sent invoices"
name="not_sent_invoices"
domain="[('move_sent_state', '=', 'not_sent')]"
invisible="context.get('default_move_type') in ('in_invoice', 'in_refund', 'in_receipt')"/>
<separator/>
<filter name="out_invoice"
string="Invoices"
Expand Down
2 changes: 1 addition & 1 deletion addons/l10n_it_edi/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ def action_l10n_it_edi_send(self):
self.invalidate_recordset(fnames=['l10n_it_edi_attachment_id', 'l10n_it_edi_attachment_file'])
self.message_post(attachment_ids=self.l10n_it_edi_attachment_id.ids)
self._l10n_it_edi_send({self: attachment_vals})
self.is_move_sent = True
self.move_sent_state = 'sent'

def action_check_l10n_it_edi(self):
self.ensure_one()
Expand Down
2 changes: 1 addition & 1 deletion addons/l10n_it_edi/views/l10n_it_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
<button name="action_l10n_it_edi_send"
type="object"
string="Send Tax Integration"
invisible="state != 'posted' or not l10n_it_edi_is_self_invoice or is_move_sent or country_code != 'IT'"
invisible="state != 'posted' or not l10n_it_edi_is_self_invoice or move_sent_state == 'sent' or country_code != 'IT'"
data-hotkey="y"/>
</xpath>
<xpath expr="//sheet" position="before">
Expand Down
2 changes: 1 addition & 1 deletion addons/l10n_tr_nilvera_einvoice/models/account_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def _l10n_tr_nilvera_submit_document(self, xml_file, endpoint, post_series=True)
)

if response.status_code == 200:
self.is_move_sent = True
self.move_sent_state = 'sent'
self.l10n_tr_nilvera_send_status = 'sent'
elif response.status_code in {401, 403}:
raise UserError(_("Oops, seems like you're unauthorised to do this. Try another API key with more rights or contact Nilvera."))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def _link_invoice_documents(self, invoices_data):
# The move needs to be put as sent only if sent by Nilvera
for invoice, invoice_data in invoices_data.items():
if invoice.company_id.country_code == 'TR':
invoice.is_move_sent = invoice.l10n_tr_nilvera_send_status == 'sent'
invoice.move_sent_state = 'sent' if invoice.l10n_tr_nilvera_send_status == 'sent' else 'not_sent'


@api.model
Expand Down
6 changes: 3 additions & 3 deletions addons/sale/models/payment_transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ def _send_invoice(self):
company_id=tx.company_id.id,
)
invoice_to_send = tx.invoice_ids.filtered(
lambda i: not i.is_move_sent and i.state == 'posted' and i._is_ready_to_be_sent()
lambda i: i.move_sent_state == 'not_sent' and i.state == 'posted' and i._is_ready_to_be_sent()
)
invoice_to_send.is_move_sent = True # Mark invoice as sent
invoice_to_send.move_sent_state = 'sent' # Mark invoice as sent
self.env['account.move.send']._generate_and_send_invoices(
invoice_to_send,
allow_raising=False,
Expand All @@ -171,7 +171,7 @@ def _cron_send_invoice(self):
('state', '=', 'done'),
('is_post_processed', '=', True),
('invoice_ids', 'in', self.env['account.move']._search([
('is_move_sent', '=', False),
('move_sent_state', '=', 'not_sent'),
('state', '=', 'posted'),
])),
('sale_order_ids.state', '=', 'sale'),
Expand Down
2 changes: 1 addition & 1 deletion addons/sale/tests/test_payment_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def test_auto_done_and_auto_invoice(self):
self.assertTrue(self.sale_order.locked)
self.assertTrue(tx.invoice_ids)
self.assertTrue(self.sale_order.invoice_ids)
self.assertTrue(tx.invoice_ids.is_move_sent)
self.assertEqual(tx.invoice_ids.move_sent_state, 'sent')

def test_so_partial_payment_no_invoice(self):
# Set automatic invoice
Expand Down