| 1 |
from odoo import _, fields, models, api |
| 2 |
|
| 3 |
|
| 4 |
class AccountJournal(models.Model): |
| 5 |
_inherit = 'account.journal' |
| 6 |
|
| 7 |
account_peppol_proxy_state = fields.Selection(related='company_id.account_peppol_proxy_state') |
| 8 |
is_peppol_journal = fields.Boolean(string="Account used for Peppol", default=False) |
| 9 |
|
| 10 |
@api.depends('account_peppol_proxy_state') |
| 11 |
def _compute_show_refresh_out_einvoices_status_button(self): |
| 12 |
|
| 13 |
super()._compute_show_refresh_out_einvoices_status_button() |
| 14 |
sender_states = self.env['account_edi_proxy_client.user']._get_can_send_domain() |
| 15 |
|
| 16 |
self.filtered(lambda j: ( |
| 17 |
j.account_peppol_proxy_state in sender_states |
| 18 |
and ( |
| 19 |
j.type == 'sale' |
| 20 |
or ( |
| 21 |
j.type == 'purchase' |
| 22 |
and j.is_self_billing |
| 23 |
) |
| 24 |
) |
| 25 |
)).show_refresh_out_einvoices_status_button = True |
| 26 |
|
| 27 |
@api.depends('is_peppol_journal', 'account_peppol_proxy_state') |
| 28 |
def _compute_show_fetch_in_einvoices_button(self): |
| 29 |
|
| 30 |
super()._compute_show_fetch_in_einvoices_button() |
| 31 |
|
| 32 |
self.filtered(lambda j: ( |
| 33 |
j.is_peppol_journal |
| 34 |
and j.account_peppol_proxy_state == 'receiver' |
| 35 |
and j.type == 'purchase' |
| 36 |
and not j.is_self_billing |
| 37 |
)).show_fetch_in_einvoices_button = True |
| 38 |
|
| 39 |
def button_fetch_in_einvoices(self): |
| 40 |
|
| 41 |
super().button_fetch_in_einvoices() |
| 42 |
edi_users = self.env['account_edi_proxy_client.user'].search([ |
| 43 |
('company_id.account_peppol_proxy_state', '=', 'receiver'), |
| 44 |
('company_id', 'in', self.company_id.ids), |
| 45 |
('proxy_type', '=', 'peppol') |
| 46 |
]) |
| 47 |
edi_users._peppol_get_new_documents() |
| 48 |
|
| 49 |
def button_refresh_out_einvoices_status(self): |
| 50 |
|
| 51 |
super().button_refresh_out_einvoices_status() |
| 52 |
can_send = self.env['account_edi_proxy_client.user']._get_can_send_domain() |
| 53 |
edi_users = self.env['account_edi_proxy_client.user'].search([ |
| 54 |
('company_id.account_peppol_proxy_state', 'in', can_send), |
| 55 |
('company_id', 'in', self.company_id.ids), |
| 56 |
('proxy_type', '=', 'peppol') |
| 57 |
]) |
| 58 |
edi_users._peppol_get_message_status() |