Add employee on cycles for running and done states
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
* Add employee on cycles for running and done states
|
||||||
* Display cost of works
|
* Display cost of works
|
||||||
|
|
||||||
Version 6.8.0 - 2023-05-01
|
Version 6.8.0 - 2023-05-01
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Imports::
|
|||||||
>>> import datetime as dt
|
>>> import datetime as dt
|
||||||
>>> from decimal import Decimal
|
>>> from decimal import Decimal
|
||||||
>>> from proteus import Model, Wizard
|
>>> from proteus import Model, Wizard
|
||||||
>>> from trytond.tests.tools import activate_modules
|
>>> from trytond.tests.tools import activate_modules, set_user
|
||||||
>>> from trytond.modules.company.tests.tools import create_company, \
|
>>> from trytond.modules.company.tests.tools import create_company, \
|
||||||
... get_company
|
... get_company
|
||||||
|
|
||||||
@@ -17,6 +17,11 @@ Activate modules::
|
|||||||
|
|
||||||
>>> config = activate_modules('production_work')
|
>>> config = activate_modules('production_work')
|
||||||
|
|
||||||
|
>>> Employee = Model.get('company.employee')
|
||||||
|
>>> Group = Model.get('res.group')
|
||||||
|
>>> Party = Model.get('party.party')
|
||||||
|
>>> User = Model.get('res.user')
|
||||||
|
|
||||||
Create company::
|
Create company::
|
||||||
|
|
||||||
>>> _ = create_company()
|
>>> _ = create_company()
|
||||||
@@ -145,6 +150,24 @@ Create an Inventory::
|
|||||||
>>> inventory.state
|
>>> inventory.state
|
||||||
'done'
|
'done'
|
||||||
|
|
||||||
|
Create production user::
|
||||||
|
|
||||||
|
>>> production_user = User()
|
||||||
|
>>> production_user.name = "Production"
|
||||||
|
>>> production_user.login = 'production'
|
||||||
|
>>> production_user.groups.extend(Group.find([
|
||||||
|
... ('name', '=', 'Production'),
|
||||||
|
... ]))
|
||||||
|
>>> employee_party = Party(name="Employee")
|
||||||
|
>>> employee_party.save()
|
||||||
|
>>> employee = Employee(party=employee_party)
|
||||||
|
>>> employee.save()
|
||||||
|
>>> production_user.employees.append(employee)
|
||||||
|
>>> production_user.employee = employee
|
||||||
|
>>> production_user.save()
|
||||||
|
|
||||||
|
>>> set_user(production_user)
|
||||||
|
|
||||||
Make a production::
|
Make a production::
|
||||||
|
|
||||||
>>> Production = Model.get('production')
|
>>> Production = Model.get('production')
|
||||||
@@ -197,17 +220,23 @@ Run works::
|
|||||||
>>> cycle1.click('run')
|
>>> cycle1.click('run')
|
||||||
>>> cycle1.state
|
>>> cycle1.state
|
||||||
'running'
|
'running'
|
||||||
|
>>> cycle1.run_by == employee
|
||||||
|
True
|
||||||
>>> work1.reload()
|
>>> work1.reload()
|
||||||
>>> work1.state
|
>>> work1.state
|
||||||
'running'
|
'running'
|
||||||
>>> cycle1.click('do')
|
>>> cycle1.click('do')
|
||||||
>>> cycle1.state
|
>>> cycle1.state
|
||||||
'done'
|
'done'
|
||||||
|
>>> cycle1.done_by == employee
|
||||||
|
True
|
||||||
>>> work1.reload()
|
>>> work1.reload()
|
||||||
>>> work1.state
|
>>> work1.state
|
||||||
'finished'
|
'finished'
|
||||||
>>> cycle2 = work2.cycles.new()
|
>>> cycle2 = work2.cycles.new()
|
||||||
>>> cycle2.click('cancel')
|
>>> cycle2.click('cancel')
|
||||||
|
>>> cycle2.cancelled_by == employee
|
||||||
|
True
|
||||||
>>> cycle2.state
|
>>> cycle2.state
|
||||||
'cancelled'
|
'cancelled'
|
||||||
>>> work2.reload()
|
>>> work2.reload()
|
||||||
|
|||||||
@@ -7,6 +7,10 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
<label name="duration"/>
|
<label name="duration"/>
|
||||||
<field name="duration"/>
|
<field name="duration"/>
|
||||||
<newline/>
|
<newline/>
|
||||||
|
<label name="run_by"/>
|
||||||
|
<field name="run_by"/>
|
||||||
|
<label name="done_by"/>
|
||||||
|
<field name="done_by"/>
|
||||||
<label name="state"/>
|
<label name="state"/>
|
||||||
<field name="state"/>
|
<field name="state"/>
|
||||||
<group col="-1" colspan="2" id="buttons">
|
<group col="-1" colspan="2" id="buttons">
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ from trytond.model import (
|
|||||||
DeactivableMixin, Index, ModelSQL, ModelView, Workflow, fields,
|
DeactivableMixin, Index, ModelSQL, ModelView, Workflow, fields,
|
||||||
sequence_ordered, tree)
|
sequence_ordered, tree)
|
||||||
from trytond.model.exceptions import AccessError
|
from trytond.model.exceptions import AccessError
|
||||||
|
from trytond.modules.company.model import employee_field, set_employee
|
||||||
from trytond.modules.product import price_digits, round_price
|
from trytond.modules.product import price_digits, round_price
|
||||||
from trytond.pool import Pool
|
from trytond.pool import Pool
|
||||||
from trytond.pyson import Bool, Eval, If, TimeDelta
|
from trytond.pyson import Bool, Eval, If, TimeDelta
|
||||||
@@ -321,6 +322,18 @@ class WorkCycle(Workflow, ModelSQL, ModelView):
|
|||||||
'readonly': Eval('state').in_(['done', 'draft', 'cancelled']),
|
'readonly': Eval('state').in_(['done', 'draft', 'cancelled']),
|
||||||
})
|
})
|
||||||
cost = fields.Numeric('Cost', digits=price_digits, readonly=True)
|
cost = fields.Numeric('Cost', digits=price_digits, readonly=True)
|
||||||
|
company = fields.Function(
|
||||||
|
fields.Many2One('company.company', "Company"),
|
||||||
|
'on_change_with_company', searcher='search_company')
|
||||||
|
run_by = employee_field("Run By", states={
|
||||||
|
'readonly': Eval('state') != 'draft',
|
||||||
|
})
|
||||||
|
done_by = employee_field("Done By", states={
|
||||||
|
'readonly': Eval('state').in_(['draft', 'running']),
|
||||||
|
})
|
||||||
|
cancelled_by = employee_field("Cancelled By", states={
|
||||||
|
'readonly': Eval('state').in_(['draft', 'running']),
|
||||||
|
})
|
||||||
state = fields.Selection([
|
state = fields.Selection([
|
||||||
('draft', 'Draft'),
|
('draft', 'Draft'),
|
||||||
('running', 'Running'),
|
('running', 'Running'),
|
||||||
@@ -361,10 +374,28 @@ class WorkCycle(Workflow, ModelSQL, ModelView):
|
|||||||
def default_state(cls):
|
def default_state(cls):
|
||||||
return 'draft'
|
return 'draft'
|
||||||
|
|
||||||
|
@fields.depends('work', '_parent_work.company')
|
||||||
|
def on_change_with_company(self, name=None):
|
||||||
|
if self.work and self.work.company:
|
||||||
|
return self.work.company.id
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def search_company(cls, name, clause):
|
||||||
|
return [('work.' + clause[0], *clause[1:])]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def copy(cls, cycles, default=None):
|
||||||
|
default = default.copy() if default is not None else {}
|
||||||
|
default.setdefault('run_by')
|
||||||
|
default.setdefault('done_by')
|
||||||
|
default.setdefault('cancelled_by')
|
||||||
|
return super().copy(cycles, default=default)
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@ModelView.button
|
@ModelView.button
|
||||||
@set_work_state
|
@set_work_state
|
||||||
@Workflow.transition('cancelled')
|
@Workflow.transition('cancelled')
|
||||||
|
@set_employee('cancelled_by')
|
||||||
def cancel(cls, cycles):
|
def cancel(cls, cycles):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -372,6 +403,7 @@ class WorkCycle(Workflow, ModelSQL, ModelView):
|
|||||||
@ModelView.button
|
@ModelView.button
|
||||||
@set_work_state
|
@set_work_state
|
||||||
@Workflow.transition('running')
|
@Workflow.transition('running')
|
||||||
|
@set_employee('run_by')
|
||||||
def run(cls, cycles):
|
def run(cls, cycles):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -379,6 +411,7 @@ class WorkCycle(Workflow, ModelSQL, ModelView):
|
|||||||
@ModelView.button
|
@ModelView.button
|
||||||
@set_work_state
|
@set_work_state
|
||||||
@Workflow.transition('done')
|
@Workflow.transition('done')
|
||||||
|
@set_employee('done_by')
|
||||||
def do(cls, cycles):
|
def do(cls, cycles):
|
||||||
now = datetime.datetime.now()
|
now = datetime.datetime.now()
|
||||||
for cycle in cycles:
|
for cycle in cycles:
|
||||||
|
|||||||
@@ -331,7 +331,7 @@ this repository contains the full copyright notices and license terms. -->
|
|||||||
</record>
|
</record>
|
||||||
<record model="ir.rule" id="rule_work_cycle_companies">
|
<record model="ir.rule" id="rule_work_cycle_companies">
|
||||||
<field name="domain"
|
<field name="domain"
|
||||||
eval="[('work.company', 'in', Eval('companies', []))]"
|
eval="[('company', 'in', Eval('companies', []))]"
|
||||||
pyson="1"/>
|
pyson="1"/>
|
||||||
<field name="rule_group" ref="rule_group_work_cycle_companies"/>
|
<field name="rule_group" ref="rule_group_work_cycle_companies"/>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
Reference in New Issue
Block a user