19.0 vanilla

This commit is contained in:
Ernad Husremovic 2026-03-09 09:30:07 +01:00
parent ba20ce7443
commit 768b70e05e
2357 changed files with 1057103 additions and 712486 deletions

View file

@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
from . import res_company
from . import res_config_settings
from . import account_move
from . import account_move_send
from . import res_partner

View file

@ -0,0 +1,13 @@
from odoo import api, models
class AccountMove(models.Model):
_inherit = "account.move"
@api.ondelete(at_uninstall=False)
def unlink_snailmail_letters(self):
snailmail_letters = self.env['snailmail.letter'].search([
('model', '=', 'account.move'),
('res_id', 'in', self.ids),
])
snailmail_letters.unlink()

View file

@ -0,0 +1,67 @@
from odoo import api, models, _
class AccountMoveSend(models.AbstractModel):
_inherit = 'account.move.send'
# -------------------------------------------------------------------------
# ALERTS
# -------------------------------------------------------------------------
def _get_alerts(self, moves, moves_data):
# EXTENDS 'account'
alerts = super()._get_alerts(moves, moves_data)
if snailmail_moves_without_valid_address := moves.filtered(
lambda m: 'snailmail' in moves_data[m]['sending_methods'] and not self.env['snailmail.letter']._is_valid_address(m.partner_id)
):
alerts['snailmail_account_partner_invalid_address'] = {
'level': 'danger' if len(snailmail_moves_without_valid_address) == 1 else 'warning',
'message': _(
"The partners on the following invoices have no valid address, "
"so those invoices will not be sent: %s",
", ".join(snailmail_moves_without_valid_address.mapped('name'))
),
'action_text': _("View Invoice(s)"),
'action': snailmail_moves_without_valid_address._get_records_action(name=_("Check Invoice(s)")),
}
return alerts
# -------------------------------------------------------------------------
# HELPERS
# -------------------------------------------------------------------------
@api.model
def _prepare_snailmail_letter_values(self, move):
return {
'partner_id': move.partner_id.id,
'model': 'account.move',
'res_id': move.id,
'company_id': move.company_id.id,
'report_template': self.env['ir.actions.report']._get_report('account.account_invoices').id
}
# -------------------------------------------------------------------------
# SENDING METHODS
# -------------------------------------------------------------------------
def _is_applicable_to_move(self, method, move, **move_data):
# EXTENDS 'account'
if method == 'snailmail':
return self.env['snailmail.letter']._is_valid_address(move.partner_id)
else:
return super()._is_applicable_to_move(method, move, **move_data)
def _hook_if_success(self, moves_data, from_cron=False):
# EXTENDS 'account'
to_send = {
move: move_data
for move, move_data in moves_data.items()
if 'snailmail' in move_data['sending_methods'] and self._is_applicable_to_move('snailmail', move, **move_data)
}
if to_send:
self.env['snailmail.letter'].create([
{
'user_id': move_data.get('author_user_id') or self.env.user.id,
**self._prepare_snailmail_letter_values(move),
}
for move, move_data in to_send.items()
])\
._snailmail_print(immediate=False)
super()._hook_if_success(moves_data, from_cron)

View file

@ -1,10 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class Company(models.Model):
_inherit = "res.company"
invoice_is_snailmail = fields.Boolean(string='Send by Post', default=False)

View file

@ -1,10 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'
invoice_is_snailmail = fields.Boolean(string='Send by Post', related='company_id.invoice_is_snailmail', readonly=False)

View file

@ -0,0 +1,9 @@
from odoo import fields, models
class ResPartner(models.Model):
_inherit = 'res.partner'
invoice_sending_method = fields.Selection(
selection_add=[('snailmail', 'by Post')],
)