Skip to content
Permalink
Browse files

[IMP] expense track values:

At the moment, no changes applied to an expense/expense-report is mentioned in its chatter. It is interesting to indicate the most important changes, as expenses can be quite a sensitive subject in some cases.

Thus we are adding the tracking argument to the following fields:

hr.expense:
	-name
	-total_amount
	-payment_mode
	-employee_id

hr.expense.sheet
	-name
	-employee_id
	-payment_mode
	-total_amount

task 1978580
  • Loading branch information...
MaxLarue committed Jun 5, 2019
1 parent 9ff7758 commit 7bd9d69f9c7007422ed741a1dab240ce05f336b5
@@ -43,18 +43,18 @@ def _get_employee_id_domain(self):
res = [('id', '=', employee.id), '|', ('company_id', '=', False), ('company_id', '=', employee.company_id.id)]
return res

name = fields.Char('Description', readonly=True, required=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]})
name = fields.Char('Description', readonly=True, required=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]}, tracking=True)
date = fields.Date(readonly=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]}, default=fields.Date.context_today, string="Date")
employee_id = fields.Many2one('hr.employee', string="Employee", required=True, readonly=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]}, default=_default_employee_id, domain=lambda self: self._get_employee_id_domain())
employee_id = fields.Many2one('hr.employee', string="Employee", required=True, readonly=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]}, default=_default_employee_id, domain=lambda self: self._get_employee_id_domain(), tracking=True)
# product_id not required to allow create an expense without product via mail alias, but should be required on the view.
product_id = fields.Many2one('product.product', string='Product', readonly=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]}, domain="[('can_be_expensed', '=', True), '|', ('company_id', '=', False), ('company_id', '=', company_id)]")
product_id = fields.Many2one('product.product', string='Product', readonly=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]}, domain="[('can_be_expensed', '=', True), '|', ('company_id', '=', False), ('company_id', '=', company_id)]", tracking=True)
product_uom_id = fields.Many2one('uom.uom', string='Unit of Measure', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=_default_product_uom_id, domain="[('category_id', '=', product_uom_category_id)]")
product_uom_category_id = fields.Many2one(related='product_id.uom_id.category_id', readonly=True)
unit_amount = fields.Float("Unit Price", readonly=True, required=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]}, digits='Product Price')
quantity = fields.Float(required=True, readonly=True, states={'draft': [('readonly', False)], 'reported': [('readonly', False)], 'refused': [('readonly', False)]}, digits='Product Unit of Measure', default=1)
tax_ids = fields.Many2many('account.tax', 'expense_tax', 'expense_id', 'tax_id', domain="[('company_id', '=', company_id)]", string='Taxes')
untaxed_amount = fields.Float("Subtotal", store=True, compute='_compute_amount', digits='Account')
total_amount = fields.Monetary("Total", compute='_compute_amount', store=True, currency_field='currency_id')
total_amount = fields.Monetary("Total", compute='_compute_amount', store=True, currency_field='currency_id', tracking=True)
company_currency_id = fields.Many2one('res.currency', string="Report Company Currency", related='sheet_id.currency_id', store=True, readonly=False)
total_amount_company = fields.Monetary("Total (Company Currency)", compute='_compute_total_amount_company', store=True, currency_field='company_currency_id')
company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)], 'refused': [('readonly', False)]}, default=lambda self: self.env.company)
@@ -66,7 +66,7 @@ def _get_employee_id_domain(self):
payment_mode = fields.Selection([
("own_account", "Employee (to reimburse)"),
("company_account", "Company")
], default='own_account', states={'done': [('readonly', True)], 'approved': [('readonly', True)], 'reported': [('readonly', True)]}, string="Paid By")
], default='own_account', states={'done': [('readonly', True)], 'approved': [('readonly', True)], 'reported': [('readonly', True)]}, string="Paid By", tracking=True)
attachment_number = fields.Integer('Number of Attachments', compute='_compute_attachment_number')
state = fields.Selection([
('draft', 'To Submit'),
@@ -103,6 +103,7 @@ def _compute_amount(self):
taxes = expense.tax_ids.compute_all(expense.unit_amount, expense.currency_id, expense.quantity, expense.product_id, expense.employee_id.user_id.partner_id)
expense.total_amount = taxes.get('total_included')


@api.depends('date', 'total_amount', 'company_currency_id')
def _compute_total_amount_company(self):
for expense in self:
@@ -647,7 +648,7 @@ def _default_journal_id(self):
def _default_bank_journal_id(self):
return self.env['account.journal'].search([('type', 'in', ['cash', 'bank'])], limit=1)

name = fields.Char('Expense Report Summary', required=True)
name = fields.Char('Expense Report Summary', required=True, tracking=True)
expense_line_ids = fields.One2many('hr.expense', 'sheet_id', string='Expense Lines', states={'approve': [('readonly', True)], 'done': [('readonly', True)], 'post': [('readonly', True)]}, copy=False)
state = fields.Selection([
('draft', 'Draft'),
@@ -657,11 +658,11 @@ def _default_bank_journal_id(self):
('done', 'Paid'),
('cancel', 'Refused')
], string='Status', index=True, readonly=True, tracking=True, copy=False, default='draft', required=True, help='Expense Report State')
employee_id = fields.Many2one('hr.employee', string="Employee", required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env['hr.employee'].search([('user_id', '=', self.env.uid)], domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", limit=1))
employee_id = fields.Many2one('hr.employee', string="Employee", required=True, readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env['hr.employee'].search([('user_id', '=', self.env.uid), '|', ('company_id', '=', False), ('company_id', '=', 'company_id')], limit=1), tracking=True)
address_id = fields.Many2one('res.partner', domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]", string="Employee Home Address")
payment_mode = fields.Selection(related='expense_line_ids.payment_mode', default='own_account', readonly=True, string="Paid By")
payment_mode = fields.Selection(related='expense_line_ids.payment_mode', default='own_account', readonly=True, string="Paid By", tracking=True)
user_id = fields.Many2one('res.users', 'Manager', readonly=True, copy=False, states={'draft': [('readonly', False)]}, tracking=True)
total_amount = fields.Monetary('Total Amount', currency_field='currency_id', compute='_compute_amount', store=True)
total_amount = fields.Monetary('Total Amount', currency_field='currency_id', compute='_compute_amount', store=True, tracking=True)
company_id = fields.Many2one('res.company', string='Company', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company)
currency_id = fields.Many2one('res.currency', string='Currency', readonly=True, states={'draft': [('readonly', False)]}, default=lambda self: self.env.company.currency_id)
attachment_number = fields.Integer(compute='_compute_attachment_number', string='Number of Attachments')
@@ -501,7 +501,8 @@
<notebook>
<page name="expenses" string="Expense">
<field name="expense_line_ids" nolabel="1" widget="many2many" domain="[('state', '=', 'draft'), ('employee_id', '=', employee_id)]" options="{'reload_on_button': True}" context="{'form_view_ref' : 'hr_expense.hr_expense_view_form_without_header', 'expense_adding_line': True}">
<tree decoration-danger="is_refused">
<tree decoration-danger="is_refused" editable="bottom">
<field name="company_id" invisible="1"/>
<field name="date"/>
<field name="name"/>
<field name="state" invisible="1"/>
@@ -512,7 +513,10 @@
<button name="action_get_attachment_view" string="View Attachments" type="object" icon="fa-paperclip"/>
<field name="tax_ids" widget="many2many_tags" groups="account.group_account_user"/>
<field name="currency_id" invisible="1"/>
<field name="total_amount"/>
<field name="product_id" />
<field name="quantity" />
<field name="unit_amount" />
<field name="total_amount" string="Total" readonly="1"/>
<field name="company_currency_id" invisible="1"/>
<field name="total_amount_company" groups="base.group_multi_currency"/>
<field name="is_refused" invisible="True"/>
@@ -11,7 +11,8 @@ class Expense(models.Model):
'sale.order', string='Reinvoice Customer', readonly=True,
states={'draft': [('readonly', False)], 'reported': [('readonly', False)]},
domain="[('state', '=', 'sale'), ('company_id', '=', company_id)]",
help="If the product has an expense policy, it will be reinvoiced on this sales order")
help="If the product has an expense policy, it will be reinvoiced on this sales order",
tracking=True)
can_be_reinvoiced = fields.Boolean("Can be reinvoiced", compute='_compute_can_be_reinvoiced')

@api.depends('product_id')

0 comments on commit 7bd9d69

Please sign in to comment.
You can’t perform that action at this time.