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 @@
# -*- coding: utf-8 -*-
from . import account_invoice_send
from . import snailmail_confirm_invoice_send
from . import account_move_send_batch_wizard

View file

@ -1,99 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models, Command, _
from odoo.exceptions import UserError
class AccountInvoiceSend(models.TransientModel):
_name = 'account.invoice.send'
_inherit = 'account.invoice.send'
_description = 'Account Invoice Send'
partner_id = fields.Many2one('res.partner', compute='_get_partner', string='Partner')
snailmail_is_letter = fields.Boolean('Send by Post',
help='Print and post the invoice by snailmail',
default=lambda self: self.env.company.invoice_is_snailmail)
snailmail_cost = fields.Float(string='Stamp(s)', compute='_compute_snailmail_cost', readonly=True)
invalid_addresses = fields.Integer('Invalid Addresses Count', compute='_compute_invalid_addresses')
invalid_invoices = fields.Integer('Invalid Invoices Count', compute='_compute_invalid_addresses')
invalid_partner_ids = fields.Many2many('res.partner', string='Invalid Addresses', compute='_compute_invalid_addresses')
@api.depends('invoice_ids')
def _compute_invalid_addresses(self):
for wizard in self:
if any(not invoice.partner_id for invoice in wizard.invoice_ids):
raise UserError(_('You cannot send an invoice which has no partner assigned.'))
invalid_invoices = wizard.invoice_ids.filtered(lambda i: not self.env['snailmail.letter']._is_valid_address(i.partner_id))
wizard.invalid_invoices = len(invalid_invoices)
invalid_partner_ids = invalid_invoices.partner_id.ids
wizard.invalid_addresses = len(invalid_partner_ids)
wizard.invalid_partner_ids = [Command.set(invalid_partner_ids)]
@api.depends('invoice_ids')
def _get_partner(self):
self.partner_id = self.env['res.partner']
for wizard in self:
if wizard.invoice_ids and len(wizard.invoice_ids) == 1:
wizard.partner_id = wizard.invoice_ids.partner_id.id
@api.depends('snailmail_is_letter')
def _compute_snailmail_cost(self):
for wizard in self:
wizard.snailmail_cost = len(wizard.invoice_ids.ids)
def snailmail_print_action(self):
self.ensure_one()
letters = self.env['snailmail.letter']
for invoice in self.invoice_ids:
letter = self.env['snailmail.letter'].create({
'partner_id': invoice.partner_id.id,
'model': 'account.move',
'res_id': invoice.id,
'user_id': self.env.user.id,
'company_id': invoice.company_id.id,
'report_template': self.env.ref('account.account_invoices').id
})
letters |= letter
self.invoice_ids.filtered(lambda inv: not inv.is_move_sent).write({'is_move_sent': True})
if len(self.invoice_ids) == 1:
letters._snailmail_print()
else:
letters._snailmail_print(immediate=False)
def send_and_print_action(self):
if self.snailmail_is_letter:
if self.env['snailmail.confirm.invoice'].show_warning():
wizard = self.env['snailmail.confirm.invoice'].create({'model_name': _('Invoice'), 'invoice_send_id': self.id})
return wizard.action_open()
self._print_action()
return self.send_and_print()
def _print_action(self):
if not self.snailmail_is_letter:
return
if self.invalid_addresses and self.composition_mode == "mass_mail":
self.notify_invalid_addresses()
self.snailmail_print_action()
def send_and_print(self):
res = super(AccountInvoiceSend, self).send_and_print_action()
return res
def notify_invalid_addresses(self):
self.ensure_one()
self.env['bus.bus']._sendone(self.env.user.partner_id, 'snailmail_invalid_address', {
'title': _("Invalid Addresses"),
'message': _("%s of the selected invoice(s) had an invalid address and were not sent", self.invalid_invoices),
})
def invalid_addresses_action(self):
return {
'name': _('Invalid Addresses'),
'type': 'ir.actions.act_window',
'view_mode': 'kanban,tree,form',
'res_model': 'res.partner',
'domain': [('id', 'in', self.invalid_partner_ids.ids)],
}

View file

@ -1,53 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="account_invoice_send_inherit_account_wizard_form">
<field name="name">account.invoice.send.form.inherited.snailmail</field>
<field name="model">account.invoice.send</field>
<field name="inherit_id" ref="account.account_invoice_send_wizard_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@name='option_email']" position='before'>
<div name="option_letter">
<field name="invalid_addresses" invisible="1"/>
<div name="option" class="text-start d-inline-block">
<field name="snailmail_is_letter" />
<b><label for="snailmail_is_letter"/></b>
</div>
<span attrs="{'invisible': [('snailmail_is_letter','=', False)]}">
<span class="mr4" attrs="{'invisible': [('snailmail_cost', '=', 0)]}">
<b>(
<span>
<field name="snailmail_cost" options="{'digits':[0,0]}" class="mr4"/>
<label for="snailmail_cost" class="mr4"/>
</span>
<i class="fa fa-info-circle" role="img" aria-label="Warning" title="Make sure you have enough Stamps on your account."/>
)</b>
</span>
<span class="text-end d-inline-block " attrs="{'invisible': ['|', ('composition_mode', '=', 'mass_mail'), ('partner_id', '=', False)]}" name="address">
<span class="text-muted" attrs="{'invisible': [('invalid_addresses', '!=', 0)]}"> to: </span>
<span class="text-danger" attrs="{'invisible': [('invalid_addresses', '=', 0)]}"> The customer's address is incomplete: </span>
<field name="partner_id" readonly="1" force_save="1" context="{'show_address': 1, 'address_inline': 1}" options="{'always_reload': True, 'no_quick_create': True}"/>
</span>
<span attrs="{'invisible': ['|', ('composition_mode', '!=', 'mass_mail'), ('invalid_addresses', '=', 0)]}">
<span class="text-danger">
Some customer addresses are incomplete.
</span>
<button type="object" name="invalid_addresses_action" class="btn btn-link" role="button"><field name="invalid_addresses" readonly="1" options="{'digits':[0,0]}"/> Contacts</button>
</span>
</span>
</div>
</xpath>
<xpath expr="//footer/button[hasclass('send_and_print')]" position='attributes'>
<attribute name="attrs">{'invisible': ['|', ('is_print', '=', False), '&amp;', '&amp;', ('is_print', '=', True), ('snailmail_is_letter', '=', False), ('is_email', '=', False)]}</attribute>
</xpath>
<xpath expr="//footer/button[hasclass('send')]" position='attributes'>
<attribute name="attrs">{'invisible': ['|', ('is_print', '=', True), '&amp;', '&amp;', ('is_print', '=', False), ('snailmail_is_letter', '=', False), ('is_email', '=', False)]}</attribute>
</xpath>
<xpath expr="//footer/button[hasclass('print')]" position='attributes'>
<attribute name="attrs">{'invisible': ['|', '|', ('is_print', '=', False), ('snailmail_is_letter', '=', True), ('is_email', '=', True)]}</attribute>
</xpath>
</field>
</record>
</data>
</odoo>

View file

@ -0,0 +1,21 @@
from odoo import _, fields, models
class AccountMoveSendBatchWizard(models.TransientModel):
_inherit = 'account.move.send.batch.wizard'
send_by_post_stamps = fields.Integer(compute='_compute_send_by_post_stamps')
def _compute_send_by_post_stamps(self):
for wizard in self:
partner_with_valid_address = wizard.move_ids.partner_id.filtered(
self.env['snailmail.letter']._is_valid_address
)
wizard.send_by_post_stamps = len(partner_with_valid_address)
def _compute_summary_data(self):
# EXTENDS 'account'
super()._compute_summary_data()
for wizard in self:
if wizard.summary_data and 'snailmail' in wizard.summary_data:
wizard.summary_data['snailmail'].update({'extra': _('(Stamps: %s)', wizard.send_by_post_stamps)})

View file

@ -1,20 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class SnailmailConfirmInvoiceSend(models.TransientModel):
_name = 'snailmail.confirm.invoice'
_inherit = ['snailmail.confirm']
_description = 'Snailmail Confirm Invoice'
invoice_send_id = fields.Many2one('account.invoice.send')
def _confirm(self):
self.ensure_one()
self.invoice_send_id._print_action()
def _continue(self):
self.ensure_one()
return self.invoice_send_id.send_and_print()