Public release from ruodoo-project: 19.0 - 2026-11-01 22:52:25 UTC
This commit is contained in:
73
ruodoo_commservice/models/create_invoice_wizard.py
Normal file
73
ruodoo_commservice/models/create_invoice_wizard.py
Normal file
@@ -0,0 +1,73 @@
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
from odoo import api, fields, models, exceptions
|
||||
|
||||
|
||||
class CommCreateInvoiceWizard(models.TransientModel):
|
||||
_name = 'comm.createinv'
|
||||
_description = 'Мастер создания счетов за период'
|
||||
|
||||
contract_ids = fields.Many2many('comm.contract', string='Договоры', required=True)
|
||||
line_ids = fields.Many2many('comm.wizardline', string='Результат работы')
|
||||
year = fields.Integer(
|
||||
string='Год', required=True,
|
||||
default=lambda self: datetime.today().year,
|
||||
)
|
||||
month = fields.Integer(
|
||||
string='Месяц', required=True,
|
||||
default=lambda self: datetime.today().month,
|
||||
)
|
||||
invoice_created = fields.Boolean(string='Счета уже создавались')
|
||||
message = fields.Char(string='Сообщение')
|
||||
|
||||
@api.constrains('year', 'month')
|
||||
def _check_period(self):
|
||||
for rec in self:
|
||||
if rec.year < 2018 or rec.month < 1 or rec.month > 12:
|
||||
raise exceptions.ValidationError(
|
||||
'Введите корректные данные для периода!'
|
||||
)
|
||||
|
||||
def fill_contracts(self):
|
||||
self.ensure_one()
|
||||
contracts = self.env['comm.contract'].search([('state', '=', 'open')])
|
||||
self.contract_ids = [(6, 0, contracts.ids)]
|
||||
return self._reopen_form()
|
||||
|
||||
def do_creation(self):
|
||||
self.ensure_one()
|
||||
WizardLine = self.env['comm.wizardline']
|
||||
for contract in self.contract_ids:
|
||||
new_line = WizardLine.create({'contract_id': contract.id})
|
||||
self.line_ids |= new_line
|
||||
new_line.result = contract.create_invoice(
|
||||
year=self.year, month=self.month,
|
||||
)
|
||||
if self.line_ids:
|
||||
self.invoice_created = True
|
||||
self.message = (
|
||||
'Обработка завершена. Если имеются сообщения, что не удалось '
|
||||
'вычислить потребление, это означает, что не были внесены данные '
|
||||
'по счётчикам. Как только данные подадут, начисление автоматически '
|
||||
'учтёт весь расход.'
|
||||
)
|
||||
return self._reopen_form()
|
||||
|
||||
def _reopen_form(self):
|
||||
self.ensure_one()
|
||||
return {
|
||||
'type': 'ir.actions.act_window',
|
||||
'res_model': self._name,
|
||||
'res_id': self.id,
|
||||
'view_mode': 'form',
|
||||
'target': 'new',
|
||||
}
|
||||
|
||||
|
||||
class CommCreateInvoiceWizardLine(models.TransientModel):
|
||||
_name = 'comm.wizardline'
|
||||
_description = 'Строка результата мастера создания счетов'
|
||||
|
||||
contract_id = fields.Many2one('comm.contract', string='Договор')
|
||||
result = fields.Char(string='Результат')
|
||||
Reference in New Issue
Block a user