跳至內容
選單
此問題已被標幟
2 回覆
5341 瀏覽次數

Hi,

I want to configure the Invoice due date as 30 days from the date of creating the Invoice.

Suppose I create an invoice today then the due date should be 30 days from today's date automatically.

How can I achieve this?


頭像
捨棄
最佳答案

You can do this manually by changing the Due Date or Payment Terms on the invoice itself. 

Now in order to do this automatically you can set Payment Terms per customer.


頭像
捨棄
作者

I want to do it automatically. so that, whenever an invoice is created the due date will be 30 days

When you create an invoice and select a customer, the payment term will be set to whatever you defined for that customer. So if you set it to 30 days for a customer then this will be automatically applied to all new invoices for that customer.

作者

I want the due date to be 30 days not a payment term. so that I can follow the invoices as per due date.

If you set the payment term to 30 days then this will also set the due date to 30 days from today. Is there any specific reason you don't want to set the payment term?

作者

Yes, I don't want to use payment terms and It requires code customization.
so whenever a user wants to modify he can go to configuration and change the no. of days there in the setting itself.
As we have for the sales quotation.

最佳答案

Hi,

Change the _compute_invoice_date_due function
 Try this code:

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

    invoice_date_due = fields.Date(
        string='Due Date',
        compute='_compute_invoice_date_due', store=True, readonly=False,
        index=True,
        copy=False,
    )

    @api.depends('needed_terms')
    def _compute_invoice_date_due(self):
        due_date = fields.Date.context_today(self)+ timedelta(days=30)
        for move in self:
            move.invoice_date_due = move.needed_terms and max(
                (k['date_maturity'] for k in move.needed_terms.keys() if k),
                default=False,
            ) or move.invoice_date_due or due_date


Hope it helps

頭像
捨棄
作者

I need help on this

I created a field in the configuration.

from odoo import api, fields, models, _

class ResConfigSettings(models.TransientModel):
_inherit = 'res.config.settings'

invoice_validity_days = fields.Integer(
related='invoice_date_due.invoice_validity_days',
readonly=False)

@api.onchange('invoice_validity_days')
def _onchange_invoice_validity_days(self):
if self.invoice_validity_days < 0:
self.quotation_validity_days = self.env['res.company'].default_get(
['invoice_validity_days']
)['invoice_validity_days']
return {
'warning': {
'title': _("Warning"),
'message': _("Invoice Validity is required and must be greater or equal to 0."),
},
}

In Views

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<data>
<record id="res_config_settings_view_form_inherit" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.account</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="40"/>
<field name="inherit_id" ref="account.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//form" position="inside">
<field name="country_code" invisible="1" groups="account.group_account_manager"/>
<app data-string="Invoicing" string="Invoicing" name="account" groups="account.group_account_manager">
<field name="has_chart_of_accounts" invisible="1"/>
<field name="has_accounting_entries" invisible="1"/>
<block title="Customer Invoices" id="invoicing_settings">
<setting id="invoice_validity_days" help="Invoice validity in days">
<field name="invoice_validity_days"/>
</setting>
</block>
</app>
</xpath>
</field>
</record>
</data>
</odoo>

on change in settings, it should appear in invoice.

Please help on this

相關帖文 回覆 瀏覽次數 活動
1
7月 25
675
1
7月 25
738
0
7月 25
920
2
7月 25
1215
1
6月 25
731