summaryrefslogtreecommitdiff
path: root/custom_indoteknik/models/account_move.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 17:14:58 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 17:14:58 +0700
commit1ca3b3df3421961caec3b747a364071c80f5c7da (patch)
tree6778a1f0f3f9b4c6e26d6d87ccde16e24da6c9d6 /custom_indoteknik/models/account_move.py
parentb57188be371d36d96caac4b8d65a40745c0e972c (diff)
initial commit
Diffstat (limited to 'custom_indoteknik/models/account_move.py')
-rw-r--r--custom_indoteknik/models/account_move.py33
1 files changed, 33 insertions, 0 deletions
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'))