Skip to Content
Menu
This question has been flagged
2 Replies
3018 Views

I am trying to change the terms and conditions note inside the invoices. I know that there is a setting that can be updated concerning this field but its not working correctly. I have updated all old invoices to a new T&C note and kept the one in the sales order as is. But, when creating an invoice from an SO, the old terms and conditions are appearing on it and when creating an invoice alone without creating it from the SO then it is taking the new note I identified in the settings. Is there a function I should override in order to fix the terms & conditions? if yes, what is it?

Avatar
Discard
Best Answer

Hi , 
If you are creating the Regular Invoice , then you have to customise the below method and change the "narration" field value as per your need. 

Method :  https://github.com/odoo/odoo/blob/15.0/addons/sale/models/sale_order.py#L604

Field value : https://github.com/odoo/odoo/blob/15.0/addons/sale/models/sale_order.py#L618


And if you are creating the Invoices with Down payment functionality,  then you have to customise the below method and change the "narration" field value as per your need


Method: https://github.com/odoo/odoo/blob/15.0/addons/sale/wizard/sale_make_invoice_advance.py#L73

Field Value : https://github.com/odoo/odoo/blob/15.0/addons/sale/wizard/sale_make_invoice_advance.py#L79


Check this demo video to help you. 

     https://uploadnow.io/f/1GDCz3b


Hope it will help you.
Up vote please.

Avatar
Discard
Best Answer

When you create an invoice from SO It will take T&C of SO.

But when creating an invoice alone without creating it from the SO then it will take the default note of setting


So in your case invoice is getting T&C of SO.


If you want to change this existing behaviour you have to override this two methods.

https://github.com/odoo/odoo/blob/15.0/addons/sale/models/sale_order.py#L604​

https://github.com/odoo/odoo/blob/15.0/addons/sale/wizard/sale_make_invoice_advance.py#L73


Avatar
Discard
Author

I overrided these 2 methods and replaced: 'narration': self.note with 'narration': self.narration and order.narration but still it didn't work, do you have any idea why?

because sale order doesn't have narration field
narration field is in invoice

can you share your code so that i can help

Author

Yes I want to update the narration field inside invoice and keep it the same in the sales order. I used the same functions but updated from note to narration. Do you have any solution regarding this issue?

HI MohammadShamass, Mohammad Chamass,

If you want that invoice will take the default terms and condition as you configured.
Not the sale order terms and conditions. Then you need to comment or remove the "narration" field in the below method.

Method : https://github.com/odoo/odoo/blob/15.0/addons/sale/models/sale_order.py#L604

By removing the "narration" from the above method, Invoice will take the default
terms and condition.

Author

I commented the narration field from both methods but the problem still persists

I guess you have to check the final dictionary values at the end. It should not contains the "narration" key at all.
Please check the video i have shared in the updated answer.
Thanks

Author

Thanks for the video! But the problem is still persisting, the place you changed the terms and conditions is the same place I changed it. I also changed it from the user-defaults section. I also removed the narration fields in both functions but till now I don't have any solution that helped me.

Then, you have to check wether your custom code has used that method or not.

Author

This is the code, kindly check it:

from odoo import api, fields, models, _
from odoo.exceptions import AccessError, UserError
from odoo.tools import groupby

class AccountMoveInh(models.Model):
_inherit = 'account.move'

def _prepare_invoice(self):
"""
Prepare the dict of values to create the new invoice for a sales order. This method may be
overridden to implement custom invoice generation (making sure to call super() to establish
a clean extension chain).
"""
self.ensure_one()
journal = self.env['account.move'].with_context(default_move_type='out_invoice')._get_default_journal()
if not journal:
raise UserError(_('Please define an accounting sales journal for the company %s (%s).', self.company_id.name,
self.company_id.id))

invoice_vals = {
'ref': self.client_order_ref or '',
'move_type': 'out_invoice',
'currency_id': self.pricelist_id.currency_id.id,
'campaign_id': self.campaign_id.id,
'medium_id': self.medium_id.id,
'source_id': self.source_id.id,
'user_id': self.user_id.id,
'invoice_user_id': self.user_id.id,
'team_id': self.team_id.id,
'partner_id': self.partner_invoice_id.id,
'partner_shipping_id': self.partner_shipping_id.id,
'fiscal_position_id': (self.fiscal_position_id or self.fiscal_position_id.get_fiscal_position(
self.partner_invoice_id.id)).id,
'partner_bank_id': self.company_id.partner_id.bank_ids.filtered(
lambda bank: bank.company_id.id in (self.company_id.id, False))[:1].id,
'journal_id': journal.id, # company comes from the journal
'invoice_origin': self.name,
'invoice_payment_term_id': self.payment_term_id.id,
'payment_reference': self.reference,
'transaction_ids': [(6, 0, self.transaction_ids.ids)],
'invoice_line_ids': [],
'company_id': self.company_id.id,
}
invoice_vals=super(AccountMoveInh)._prepare_invoice(self)
return invoice_vals

def _prepare_invoice_values(self, order, name, amount, so_line):

invoice_vals = {
'ref': order.client_order_ref,
'move_type': 'out_invoice',
'invoice_origin': order.name,
'invoice_user_id': order.user_id.id,
'partner_id': order.partner_invoice_id.id,
'fiscal_position_id': (
order.fiscal_position_id or order.fiscal_position_id.get_fiscal_position(order.partner_id.id)).id,
'partner_shipping_id': order.partner_shipping_id.id,
'currency_id': order.pricelist_id.currency_id.id,
'payment_reference': order.reference,
'invoice_payment_term_id': order.payment_term_id.id,
'partner_bank_id': order.company_id.partner_id.bank_ids[:1].id,
'team_id': order.team_id.id,
'campaign_id': order.campaign_id.id,
'medium_id': order.medium_id.id,
'source_id': order.source_id.id,
'invoice_line_ids': [(0, 0, {
'name': name,
'price_unit': amount,
'quantity': 1.0,
'product_id': self.product_id.id,
'product_uom_id': so_line.product_uom.id,
'tax_ids': [(6, 0, so_line.tax_id.ids)],
'sale_line_ids': [(6, 0, [so_line.id])],
'analytic_tag_ids': [(6, 0, so_line.analytic_tag_ids.ids)],
'analytic_account_id': order.analytic_account_id.id if not so_line.display_type and order.analytic_account_id.id else False,
})],
}
invoice_vals=super(AccountMoveInh)._prepare_invoice_values(self, order, name, amount, so_line)
return invoice_vals

Related Posts Replies Views Activity
2
Jan 23
3248
2
Dec 22
2174
1
Jun 22
1569
1
May 22
1958
1
Dec 21
1455