Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2344 Lượt xem

Hi,

I want the invoice due date to be 30 days after it is created.

for that, I created an input field in res.config as we have for sales quotation validity.

When the give invoice date according that the due date should be change as per user's input in config.
but the function which i created it not being called.
Please help with this.


res.config

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

invoice_validity_days = fields.Integer('Invoice Validity', default=30, readonly=False)

res.config.views.xml

acccount_move.py

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.onchange('invoice_date')
def _compute_invoice_date_due(self):
today = fields.Date.context_today(self)
print("The Days before loop----------->", today)
for date in self:
days = date.invoice_validity_days
print("The Day in loop----------->", days)
if days > 0:
date._compute_invoice_date_due = today + timedelta(days)
else:
date._compute_invoice_date_due = False




Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ
Tác giả

It is hardcoded but I want per-user input
If I give 15 days to setting the date should be 15 days after invoice date

Bài viết liên quan Trả lời Lượt xem Hoạt động
3
thg 2 25
2687
1
thg 11 24
2431
1
thg 4 21
7595
6
thg 1 24
15260
1
thg 7 16
3979