[IMP] sale,sale_management: Add invoicing journal to SO

Add the invoicing_journal field to SO and template.
If set, this journal will be used to when creating invoice
instead of the default journal.

closes odoo/odoo#133983

Related: odoo/enterprise#46621
Related: odoo/upgrade#5119
Signed-off-by: Arnaud Joset (arj) <arj@odoo.com>
This commit is contained in:
Florian Damhaut
2023-10-20 09:35:11 +00:00
parent 59337af223
commit ff917f5478
5 changed files with 26 additions and 1 deletions
+13 -1
View File
@@ -121,6 +121,12 @@ class SaleOrder(models.Model):
string="Expiration",
compute='_compute_validity_date',
store=True, readonly=False, copy=False, precompute=True)
journal_id = fields.Many2one(
'account.journal', string="Invoicing Journal",
compute="_compute_journal_id", store=True, readonly=False, precompute=True,
domain=[('type', '=', 'sale')], check_company=True,
help="If set, the SO will invoice in this journal; "
"otherwise the sales journal with the lowest sequence is used.")
# Partner-based computes
note = fields.Html(
@@ -323,6 +329,9 @@ class SaleOrder(models.Model):
else:
order.validity_date = False
def _compute_journal_id(self):
self.journal_id = False
@api.depends('partner_id')
def _compute_note(self):
use_invoice_terms = self.env['ir.config_parameter'].sudo().get_param('account.use_invoice_terms')
@@ -1121,7 +1130,7 @@ class SaleOrder(models.Model):
"""
self.ensure_one()
return {
values = {
'ref': self.client_order_ref or '',
'move_type': 'out_invoice',
'narration': self.note,
@@ -1142,6 +1151,9 @@ class SaleOrder(models.Model):
'invoice_line_ids': [],
'user_id': self.user_id.id,
}
if self.journal_id:
values['journal_id'] = self.journal_id.id
return values
def action_view_invoice(self, invoices=False):
if not invoices:
+1
View File
@@ -720,6 +720,7 @@
</div>
<field name="partner_invoice_id" groups="!account.group_delivery_invoice_address" invisible="1"/>
<field name="analytic_account_id" context="{'default_partner_id':partner_invoice_id, 'default_name':name}" readonly="invoice_count != 0 and state == 'sale'" groups="analytic.group_analytic_accounting" force_save="1"/>
<field name="journal_id" groups="base.group_no_one" readonly="invoice_count != 0 and state == 'sale'"/>
<field name="invoice_status" invisible="state != 'sale'" groups="base.group_no_one"/>
<!-- test_event_configurator -->
<field name="invoice_status" invisible="1" groups="!base.group_no_one"/>
@@ -69,6 +69,12 @@ class SaleOrder(models.Model):
if validity_days > 0:
order.validity_date = fields.Date.context_today(order) + timedelta(validity_days)
@api.depends('sale_order_template_id')
def _compute_journal_id(self):
super()._compute_journal_id()
for order in self.filtered('sale_order_template_id'):
order.journal_id = order.sale_order_template_id.journal_id
#=== CONSTRAINT METHODS ===#
@api.constrains('company_id', 'sale_order_option_ids')
@@ -50,6 +50,11 @@ class SaleOrderTemplate(models.Model):
comodel_name='sale.order.template.option', inverse_name='sale_order_template_id',
string="Optional Products",
copy=True)
journal_id = fields.Many2one(
'account.journal', string="Invoicing Journal",
domain=[('type', '=', 'sale')], company_dependent=True, check_company=True,
help="If set, SO with this template will invoice in this journal; "
"otherwise the sales journal with the lowest sequence is used.")
#=== COMPUTE METHODS ===#
@@ -45,6 +45,7 @@
style="width: 3rem"/>
<field name="mail_template_id" context="{'default_model': 'sale.order'}"/>
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
<field name="journal_id"/>
</group>
</group>
<notebook name="main_book">