create button force_draft and set group

This commit is contained in:
Wilson Gomez 2023-04-22 12:02:11 -05:00
parent 578c5361c1
commit 886497a866
3 changed files with 42 additions and 2 deletions

View File

@ -119,6 +119,28 @@ class Payroll(metaclass=PoolMeta):
events = fields.Function(fields.One2Many('staff.event', None,
'Assistance'), 'get_events')
@classmethod
def __setup__(cls):
super(Payroll, cls).__setup__()
cls._order = [
('period', 'DESC'),
('start', 'DESC'),
]
cls._transitions |= set((
('draft', 'cancel'),
('cancel', 'draft'),
('draft', 'processed'),
('processed', 'posted'),
('posted', 'draft'),
('processed', 'draft'),
))
cls._buttons.update({
'force_draft': {
'invisible': Eval('state') != 'posted',
'depends': ['state'],
},
})
@fields.depends('end', 'date_effective')
def on_change_with_date_effective(self):
if self.end:
@ -891,13 +913,14 @@ class Payroll(metaclass=PoolMeta):
return sum(res)
@classmethod
@ModelView.button
@Workflow.transition('draft')
def draft(cls, records):
def force_draft(cls, records):
Move = Pool().get('account.move')
for payroll in records:
if payroll.move:
Move.draft([payroll.move.id])
#Move.delete([payroll.move])
# Move.delete([payroll.move])
def send_payroll_email(self):
pool = Pool()

View File

@ -352,5 +352,17 @@ this repository contains the full copyright notices and license terms. -->
<menuitem parent="staff.menu_assitants" id="menu_payroll_task"
action="act_payroll_task_form"/>
<record model="ir.model.button" id="payroll_force_draft_button">
<field name="name">force_draft</field>
<field name="string">Force Draft</field>
<field name="confirm">Are you sure you want to force draft payroll posted?</field>
<field name="model" search="[('model', '=', 'staff.payroll')]"/>
</record>
<record model="ir.model.button-res.group"
id="payroll_force_draft_button_group_account">
<field name="button" ref="payroll_force_draft_button"/>
<field name="group" ref="account.group_account"/>
</record>
</data>
</tryton>

View File

@ -27,4 +27,9 @@ this repository contains the full copyright notices and license terms. -->
<field name="events" colspan="4"/>
</page>
</xpath>
<xpath expr="/form/group[@id='state_buttons']/group[@id='buttons']/button[@name='process']"
position="after">
<button name="force_draft" string="Force Draft"
icon="tryton-forward"/>
</xpath>
</data>