From 1ca3b3df3421961caec3b747a364071c80f5c7da Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 10 May 2022 17:14:58 +0700 Subject: initial commit --- custom_indoteknik/models/account_move.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 custom_indoteknik/models/account_move.py (limited to 'custom_indoteknik/models/account_move.py') diff --git a/custom_indoteknik/models/account_move.py b/custom_indoteknik/models/account_move.py new file mode 100644 index 0000000..a5c9eaf --- /dev/null +++ b/custom_indoteknik/models/account_move.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- + +from odoo import api, fields, models, _ +from odoo.exceptions import UserError, RedirectWarning, ValidationError, except_orm, Warning +from datetime import datetime + + +class AccountMove(models.Model): + _inherit = "account.move" + + period_id = fields.Many2one(compute="_get_period", comodel_name="account.period", string="Period") + + @api.depends('invoice_date') + def _get_period(self): + for res in self: + period_id = "" + + if res.invoice_date: + period_ids = self.env['account.period'].search([ + ('start_date', '<=', res.invoice_date), + ('end_date', '>=', res.invoice_date) + ]) + + if period_ids: + period_id = period_ids[0].id + + res.period_id = period_id + + def action_post(self): + if self.period_id and self.period_id.state == "Open": + super(AccountMove, self).action_post() + else: + raise ValidationError(_('Period of this Journal has been closed')) -- cgit v1.2.3