1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
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'))
|