mirror of
https://gitlab.com/hibou-io/hibou-odoo/suite.git
synced 2025-01-20 12:37:31 +02:00
Initial commit of hr_expense_change for 11.0
This commit is contained in:
1
hr_expense_change/__init__.py
Normal file
1
hr_expense_change/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import wizard
|
||||
30
hr_expense_change/__manifest__.py
Normal file
30
hr_expense_change/__manifest__.py
Normal file
@@ -0,0 +1,30 @@
|
||||
{
|
||||
'name': 'HR Expense Change',
|
||||
'author': 'Hibou Corp. <hello@hibou.io>',
|
||||
'version': '11.0.1.0.0',
|
||||
'category': 'Employees',
|
||||
'sequence': 95,
|
||||
'summary': 'Technical foundation for changing expenses.',
|
||||
'description': """
|
||||
Technical foundation for changing expenses.
|
||||
|
||||
Creates wizard and permissions for making expense changes that can be
|
||||
handled by other individual modules.
|
||||
|
||||
This module implements, as examples, how to change the Date fields.
|
||||
|
||||
Abstractly, individual 'changes' should come from specific 'fields' or capability
|
||||
modules that handle the consequences of changing that field in whatever state the
|
||||
the invoice is currently in.
|
||||
|
||||
""",
|
||||
'website': 'https://hibou.io/',
|
||||
'depends': [
|
||||
'hr_expense',
|
||||
],
|
||||
'data': [
|
||||
'wizard/expense_change_views.xml',
|
||||
],
|
||||
'installable': True,
|
||||
'application': False,
|
||||
}
|
||||
1
hr_expense_change/tests/__init__.py
Normal file
1
hr_expense_change/tests/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import test_expense_change
|
||||
20
hr_expense_change/tests/test_expense_change.py
Normal file
20
hr_expense_change/tests/test_expense_change.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from odoo.addons.hr_expense.tests.test_expenses import TestCheckJournalEntry
|
||||
|
||||
|
||||
class TestExpenseChange(TestCheckJournalEntry):
|
||||
|
||||
def test_expense_change_basic(self):
|
||||
# posts expense and gets move ready at self.expense.account_move_id.id
|
||||
self.test_journal_entry()
|
||||
self.assertEqual(self.expense.expense_line_ids.date, self.expense.account_move_id.date)
|
||||
|
||||
ctx = {'active_model': 'hr.expense', 'active_ids': self.expense.expense_line_ids.ids}
|
||||
change = self.env['hr.expense.change'].with_context(ctx).create({})
|
||||
self.assertEqual(change.date, self.expense.expense_line_ids.date)
|
||||
|
||||
change_date = '2018-01-01'
|
||||
change.write({'date': change_date})
|
||||
|
||||
change.affect_change()
|
||||
self.assertEqual(change_date, self.expense.expense_line_ids.date)
|
||||
self.assertEqual(change_date, self.expense.account_move_id.date)
|
||||
1
hr_expense_change/wizard/__init__.py
Normal file
1
hr_expense_change/wizard/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
from . import expense_change
|
||||
55
hr_expense_change/wizard/expense_change.py
Normal file
55
hr_expense_change/wizard/expense_change.py
Normal file
@@ -0,0 +1,55 @@
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class ExpenseChangeWizard(models.TransientModel):
|
||||
_name = 'hr.expense.change'
|
||||
_description = 'Expense Change'
|
||||
|
||||
expense_id = fields.Many2one('hr.expense', string='Expense', readonly=True, required=True)
|
||||
expense_company_id = fields.Many2one('res.company', related='expense_id.company_id')
|
||||
date = fields.Date(string='Expense Date')
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields):
|
||||
rec = super(ExpenseChangeWizard, self).default_get(fields)
|
||||
context = dict(self._context or {})
|
||||
active_model = context.get('active_model')
|
||||
active_ids = context.get('active_ids')
|
||||
|
||||
# Checks on context parameters
|
||||
if not active_model or not active_ids:
|
||||
raise UserError(
|
||||
_("Programmation error: wizard action executed without active_model or active_ids in context."))
|
||||
if active_model != 'hr.expense':
|
||||
raise UserError(_(
|
||||
"Programmation error: the expected model for this action is 'hr.expense'. The provided one is '%d'.") % active_model)
|
||||
|
||||
# Checks on received expense records
|
||||
expense = self.env[active_model].browse(active_ids)
|
||||
if len(expense) != 1:
|
||||
raise UserError(_("Expense Change expects only one expense."))
|
||||
rec.update({
|
||||
'expense_id': expense.id,
|
||||
'date': expense.date,
|
||||
})
|
||||
return rec
|
||||
|
||||
def _new_expense_vals(self):
|
||||
vals = {}
|
||||
if self.expense_id.date != self.date:
|
||||
vals['date'] = self.date
|
||||
return vals
|
||||
|
||||
@api.multi
|
||||
def affect_change(self):
|
||||
self.ensure_one()
|
||||
vals = self._new_expense_vals()
|
||||
old_date = self.expense_id.date
|
||||
if vals:
|
||||
self.expense_id.write(vals)
|
||||
if 'date' in vals and self.expense_id.sheet_id.account_move_id:
|
||||
self.expense_id.sheet_id.account_move_id.write({'date': vals['date']})
|
||||
self.expense_id.sheet_id.account_move_id.line_ids\
|
||||
.filtered(lambda l: l.date_maturity == old_date).write({'date_maturity': vals['date']})
|
||||
return True
|
||||
66
hr_expense_change/wizard/expense_change_views.xml
Normal file
66
hr_expense_change/wizard/expense_change_views.xml
Normal file
@@ -0,0 +1,66 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record id="hr_expense_change_form" model="ir.ui.view">
|
||||
<field name="name">Expense Change</field>
|
||||
<field name="model">hr.expense.change</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Expense Change">
|
||||
<group>
|
||||
<group name="group_left">
|
||||
<field name="expense_id" invisible="1"/>
|
||||
<field name="expense_company_id" invisible="1"/>
|
||||
<field name="date"/>
|
||||
</group>
|
||||
<group name="group_right"/>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="affect_change" string="Change" type="object" class="btn-primary"/>
|
||||
<button string="Cancel" class="btn-default" special="cancel"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_view_hr_expense_change" model="ir.actions.act_window">
|
||||
<field name="name">Expense Change Wizard</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">hr.expense.change</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<!-- Add Button to Existing Forms -->
|
||||
<record id="hr_expense_form_view_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.expense.form.inherit</field>
|
||||
<field name="model">hr.expense</field>
|
||||
<field name="inherit_id" ref="hr_expense.hr_expense_form_view"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='state']" position="before">
|
||||
<button name="%(action_view_hr_expense_change)d" string="Change"
|
||||
type="action" class="btn-secondary"
|
||||
attrs="{'invisible': [('state', 'in', ('draft', 'refused'))]}"
|
||||
context="{'default_expense_id': active_id}"
|
||||
groups="account.group_account_manager" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_hr_expense_sheet_form_inherit" model="ir.ui.view">
|
||||
<field name="name">hr.expense.sheet.form.inherit</field>
|
||||
<field name="model">hr.expense.sheet</field>
|
||||
<field name="inherit_id" ref="hr_expense.view_hr_expense_sheet_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='expense_line_ids']/tree" position="inside">
|
||||
<field name="id" invisible="1"/>
|
||||
<button name="%(action_view_hr_expense_change)d" string="Change" icon="fa-exchange"
|
||||
type="action"
|
||||
attrs="{'invisible': [('state', 'in', ('draft', 'refused'))]}"
|
||||
context="{'default_expense_id': id}"
|
||||
groups="account.group_account_manager" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user