Set employee who validates and posts invoices

Closes #9678
This commit is contained in:
Sergi Almacellas Abellana
2023-07-06 16:27:53 +02:00
parent 1b939269dd
commit 24a4abc6ba
3 changed files with 34 additions and 0 deletions
+1
View File
@@ -1,3 +1,4 @@
* Set employee who validates and posts invoices
* Allow modification of invoice references when report is not cached * Allow modification of invoice references when report is not cached
* Add cache on invoice's amounts * Add cache on invoice's amounts
+11
View File
@@ -19,6 +19,8 @@ from trytond.model import (
fields, sequence_ordered) fields, sequence_ordered)
from trytond.model.exceptions import AccessError from trytond.model.exceptions import AccessError
from trytond.modules.account.tax import TaxableMixin from trytond.modules.account.tax import TaxableMixin
from trytond.modules.company.model import (
employee_field, reset_employee, set_employee)
from trytond.modules.currency.fields import Monetary from trytond.modules.currency.fields import Monetary
from trytond.modules.product import price_digits from trytond.modules.product import price_digits
from trytond.pool import Pool from trytond.pool import Pool
@@ -86,6 +88,12 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
'readonly': Eval('has_report_cache', False), 'readonly': Eval('has_report_cache', False),
}) })
description = fields.Char('Description', size=None, states=_states) description = fields.Char('Description', size=None, states=_states)
validated_by = employee_field(
"Validated By",
states=['validated', 'posted', 'paid', 'cancelled'])
posted_by = employee_field(
"Posted By",
states=['posted', 'paid', 'cancelled'])
state = fields.Selection([ state = fields.Selection([
('draft', "Draft"), ('draft', "Draft"),
('validated', "Validated"), ('validated', "Validated"),
@@ -1615,6 +1623,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
@classmethod @classmethod
@ModelView.button @ModelView.button
@Workflow.transition('draft') @Workflow.transition('draft')
@reset_employee('validated_by', 'posted_by')
def draft(cls, invoices): def draft(cls, invoices):
Move = Pool().get('account.move') Move = Pool().get('account.move')
@@ -1638,6 +1647,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
@classmethod @classmethod
@ModelView.button @ModelView.button
@Workflow.transition('validated') @Workflow.transition('validated')
@set_employee('validated_by')
def validate_invoice(cls, invoices): def validate_invoice(cls, invoices):
pool = Pool() pool = Pool()
Move = pool.get('account.move') Move = pool.get('account.move')
@@ -1706,6 +1716,7 @@ class Invoice(Workflow, ModelSQL, ModelView, TaxableMixin):
cls._post(invoices) cls._post(invoices)
@classmethod @classmethod
@set_employee('posted_by', when='before')
def _post(cls, invoices): def _post(cls, invoices):
pool = Pool() pool = Pool()
Move = pool.get('account.move') Move = pool.get('account.move')
@@ -30,6 +30,20 @@ Create company::
>>> tax_identifier.code = 'BE0897290877' >>> tax_identifier.code = 'BE0897290877'
>>> company.party.save() >>> company.party.save()
Set employee::
>>> User = Model.get('res.user')
>>> Party = Model.get('party.party')
>>> Employee = Model.get('company.employee')
>>> employee_party = Party(name="Employee")
>>> employee_party.save()
>>> employee = Employee(party=employee_party)
>>> employee.save()
>>> user = User(config.user)
>>> user.employees.append(employee)
>>> user.employee = employee
>>> user.save()
Create fiscal year:: Create fiscal year::
>>> fiscalyear = set_fiscalyear_invoice_sequences( >>> fiscalyear = set_fiscalyear_invoice_sequences(
@@ -167,10 +181,18 @@ Test change tax::
>>> tax_line.tax = None >>> tax_line.tax = None
>>> tax_line.tax = tax >>> tax_line.tax = tax
Validate invoice::
>>> invoice.click('validate_invoice')
>>> invoice.validated_by == employee
True
Post invoice:: Post invoice::
>>> invoice.invoice_date = today >>> invoice.invoice_date = today
>>> invoice.click('post') >>> invoice.click('post')
>>> invoice.posted_by == employee
True
>>> invoice.state >>> invoice.state
'posted' 'posted'
>>> invoice.tax_identifier.code >>> invoice.tax_identifier.code