[IMP] account_peppol: Add actions on dashboard for peppol operations

Problem
---------
User want to verify (when he want) if he has bills on Peppol and the
status of his customer invoices. Currently, the only option is wait for
a cron that runs twice a day.

Objective
---------
- Add a button in the Kanban card of the customer invoices that updates
the status of invoice send by Peppol. 
- Add a button in the Kanban card of the incoming journal that fetches
received bills on the Peppol network.

Solution
---------
This commits does several things in order to achieve the objective:
- Seperate the peppol cron function into business action and cron
function
- Add an interface on the journals so that they can call the peppol
business functions
- Add an inverse function that resets the journal `is_peppol_journal` to
False and sets that field to True on the relevant journal.
- Add a related field that checks whether the company has peppol active
- Add the buttons on the Kandan Dashboard view that call the relevant
cron function thanks to the interface. It edi users on the target
companies so that only the target companies are updated when a button is
pressed and not all companies.

task-3531222

closes odoo/odoo#137840

Signed-off-by: Florian Gilbert (flg) <flg@odoo.com>
This commit is contained in:
Antoine Boonen
2023-10-16 17:20:41 +00:00
parent 1aefc70595
commit 026205a637
6 changed files with 83 additions and 11 deletions
+1
View File
@@ -16,6 +16,7 @@
],
'data': [
'data/cron.xml',
'views/account_journal_dashboard_views.xml',
'views/account_move_views.xml',
'views/res_partner_views.xml',
'views/res_config_settings_views.xml',
+1
View File
@@ -2,6 +2,7 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import account_edi_proxy_user
from . import account_journal
from . import account_move
from . import res_company
from . import res_config_settings
@@ -63,6 +63,18 @@ class AccountEdiProxyClientUser(models.Model):
return super()._get_server_url(proxy_type, edi_mode)
# -------------------------------------------------------------------------
# CRONS
# -------------------------------------------------------------------------
def _cron_peppol_get_new_documents(self):
edi_users = self.search([('company_id.account_peppol_proxy_state', '=', 'active')])
edi_users._peppol_get_new_documents()
def _cron_peppol_get_message_status(self):
edi_users = self.search([('company_id.account_peppol_proxy_state', '=', 'active')])
edi_users._peppol_get_message_status()
# -------------------------------------------------------------------------
# BUSINESS ACTIONS
# -------------------------------------------------------------------------
@@ -75,12 +87,8 @@ class AccountEdiProxyClientUser(models.Model):
return f'{company.peppol_eas}:{company.peppol_endpoint}'
return super()._get_proxy_identification(company, proxy_type)
def _cron_peppol_get_new_documents(self):
# Retrieve all new Peppol documents for every edi user in the database
edi_users = self.env['account_edi_proxy_client.user'].search(
[('company_id.account_peppol_proxy_state', '=', 'active')])
for edi_user in edi_users:
def _peppol_get_new_documents(self):
for edi_user in self:
proxy_acks = []
try:
# request all messages that haven't been acknowledged
@@ -186,11 +194,8 @@ class AccountEdiProxyClientUser(models.Model):
{'message_uuids': proxy_acks},
)
def _cron_peppol_get_message_status(self):
edi_users = self.env['account_edi_proxy_client.user'].search(
[('company_id.account_peppol_proxy_state', '=', 'active')])
for edi_user in edi_users:
def _peppol_get_message_status(self):
for edi_user in self:
edi_user_moves = self.env['account.move'].search([
('peppol_move_state', '=', 'processing'),
('company_id', '=', edi_user.company_id.id),
@@ -0,0 +1,24 @@
# -*- coding:utf-8 -*-
from odoo import fields, models
class AccountJournal(models.Model):
_inherit = 'account.journal'
account_peppol_proxy_state = fields.Selection(related='company_id.account_peppol_proxy_state')
is_peppol_journal = fields.Boolean(string="Account used for Peppol", default=False)
def peppol_get_new_documents(self):
edi_users = self.env['account_edi_proxy_client.user'].search([
('company_id.account_peppol_proxy_state', '=', 'active'),
('company_id', 'in', self.company_id.ids),
])
edi_users._peppol_get_new_documents()
def peppol_get_message_status(self):
edi_users = self.env['account_edi_proxy_client.user'].search([
('company_id.account_peppol_proxy_state', '=', 'active'),
('company_id', 'in', self.company_id.ids),
])
edi_users._peppol_get_message_status()
@@ -66,6 +66,7 @@ class ResCompany(models.Model):
string='PEPPOL Purchase Journal',
domain=[('type', '=', 'purchase')],
compute='_compute_peppol_purchase_journal_id', store=True, readonly=False,
inverse='_inverse_peppol_purchase_journal_id',
)
# -------------------------------------------------------------------------
@@ -152,6 +153,17 @@ class ResCompany(models.Model):
else:
company.peppol_purchase_journal_id = False
def _inverse_peppol_purchase_journal_id(self):
for company in self:
# This avoid having 2 or more journals from the same company with
# `is_peppol_journal` set to True (which could occur after changes).
journals_to_reset = self.env['account.journal'].search([
('company_id', '=', company.id),
('is_peppol_journal', '=', True),
])
journals_to_reset.is_peppol_journal = False
company.peppol_purchase_journal_id.is_peppol_journal = True
@api.depends('email')
def _compute_account_peppol_contact_email(self):
for company in self:
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="account_journal_dashboard_kanban_view" model="ir.ui.view">
<field name="name">account.journal.dashboard.kanban</field>
<field name="model">account.journal</field>
<field name="inherit_id" ref="account.account_journal_dashboard_kanban_view" />
<field name="arch" type="xml">
<data>
<xpath expr="//kanban" position="inside">
<field name="is_peppol_journal" invisible="1"/>
<field name="account_peppol_proxy_state" invisible="1"/>
</xpath>
<xpath expr="//t[@id='account.JournalBodySalePurchase']//div" position="inside">
<t t-if="record.account_peppol_proxy_state.raw_value == 'active'">
<t t-if="journal_type == 'sale'">
<a type="object" name="peppol_get_message_status" groups="account.group_account_invoice">Fetch Peppol invoice status</a>
</t>
<t t-elif="journal_type == 'purchase'">
<t t-if="record.is_peppol_journal.raw_value">
<a type="object" name="peppol_get_new_documents" groups="account.group_account_invoice">Fetch from Peppol</a>
</t>
</t>
</t>
</xpath>
</data>
</field>
</record>
</odoo>