From 7b32ca8452d395578bca43c3b7efd1d3f09011cb Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Tue, 14 Jul 2015 09:24:45 +0200 Subject: [PATCH] [IMP] hr_timesheet: get rid of the "Service" product The existence of the "Service" product caused issues when users would eg. remove this product. We allow user to create timsheets even if they dont have an employee associated or if the product is missing on the employee. Those timesheets can still be invoiced using the force product field of the wizard. product_id is left blank if it cannot be deduced from the associated employee and the amount is zero. account_id is left blank we it not required anymore journal_id is set the first general journal found. --- .../account/models/account_analytic_line.py | 20 +++++------ addons/delivery/test/delivery_cost.yml | 6 ++-- addons/hr_timesheet/__openerp__.py | 1 - addons/hr_timesheet/hr_timesheet.py | 35 +++++-------------- addons/hr_timesheet/hr_timesheet_data.xml | 13 ------- addons/hr_timesheet/hr_timesheet_demo.xml | 12 ++----- addons/hr_timesheet/hr_timesheet_demo.yml | 10 +++--- addons/hr_timesheet/hr_timesheet_view.xml | 14 ++++---- .../hr_timesheet/test/hr_timesheet_data.xml | 18 ---------- .../hr_timesheet_invoice.py | 3 ++ .../test/test_hr_timesheet_invoice.yml | 20 +++++------ .../test_hr_timesheet_invoice_no_prod_tax.yml | 8 ++--- .../wizard/hr_timesheet_invoice_create.py | 2 +- .../hr_timesheet_sheet/hr_timesheet_sheet.py | 6 ++-- .../test/test_hr_timesheet_sheet.yml | 4 +-- .../wizard/hr_timesheet_current.py | 3 -- .../project_timesheet_demo.xml | 9 ++--- .../project_timesheet_view.xml | 4 +-- addons/sale_contract/models/res_config.py | 12 ------- .../test/account_analytic_analysis.yml | 8 ++--- .../sale_contract/views/res_config_view.xml | 10 ------ 21 files changed, 65 insertions(+), 153 deletions(-) delete mode 100644 addons/hr_timesheet/test/hr_timesheet_data.xml diff --git a/addons/account/models/account_analytic_line.py b/addons/account/models/account_analytic_line.py index 5b8faf5a428..c340ad0b532 100644 --- a/addons/account/models/account_analytic_line.py +++ b/addons/account/models/account_analytic_line.py @@ -11,7 +11,8 @@ class AccountAnalyticLine(models.Model): product_uom_id = fields.Many2one('product.uom', string='Unit of Measure') product_id = fields.Many2one('product.product', string='Product') - general_account_id = fields.Many2one('account.account', string='Financial Account', required=True, ondelete='restrict', domain=[('deprecated', '=', False)]) + general_account_id = fields.Many2one('account.account', string='Financial Account', ondelete='restrict', + related='move_id.account_id', store=True, domain=[('deprecated', '=', False)]) move_id = fields.Many2one('account.move.line', string='Move Line', ondelete='cascade', index=True) journal_id = fields.Many2one('account.analytic.journal', string='Analytic Journal', required=True, ondelete='restrict', index=True) code = fields.Char(size=8) @@ -30,7 +31,7 @@ class AccountAnalyticLine(models.Model): if not journal_id: j_ids = self.pool.get('account.analytic.journal').search(cr, uid, [('type', '=', 'purchase')]) journal_id = j_ids and j_ids[0] or False - if not journal_id or not prod_id: + if not journal_id: return {} product_obj = self.pool.get('product.product') analytic_journal_obj = self.pool.get('account.analytic.journal') @@ -52,18 +53,10 @@ class AccountAnalyticLine(models.Model): a = prod.property_account_expense_id.id if not a: a = prod.categ_id.property_account_expense_categ_id.id - if not a: - raise UserError(_('There is no expense account defined ' \ - 'for this product: "%s" (id:%d).') % \ - (prod.name, prod.id,)) else: a = prod.property_account_income_id.id if not a: a = prod.categ_id.property_account_income_categ_id.id - if not a: - raise UserError(_('There is no income account defined ' \ - 'for this product: "%s" (id:%d).') % \ - (prod.name, prod_id,)) flag = False # Compute based on pricetype @@ -83,7 +76,12 @@ class AccountAnalyticLine(models.Model): # price_get() will respect a 'uom' in its context, in order # to return a default price for those units ctx['uom'] = unit - amount_unit = prod.price_get(pricetype.field, context=ctx)[prod.id] + amount_unit = prod.price_get(pricetype.field, context=ctx) + if amount_unit: + amount_unit = amount_unit[prod.id] + else: + amount_unit = 0.0 + amount = amount_unit * quantity or 0.0 cur_record = self.browse(cr, uid, id, context=context) currency = cur_record.exists() and cur_record.currency_id or prod.company_id.currency_id diff --git a/addons/delivery/test/delivery_cost.yml b/addons/delivery/test/delivery_cost.yml index 2022b844759..50177e59cf7 100644 --- a/addons/delivery/test/delivery_cost.yml +++ b/addons/delivery/test/delivery_cost.yml @@ -2,7 +2,7 @@ In order to test Carrier Cost, - Create sale order with Normal Delivery Charges -- +- !record {model: sale.order, id: sale_normal_delivery_charges}: partner_id: base.res_partner_18 partner_invoice_id: base.res_partner_18 @@ -48,7 +48,7 @@ self.create_invoice(cr, uid, [wiz_id], {"active_ids": ship_ids, "active_id": ship_ids[0]}) - Create one more sale order with Free Delivery Charges -- +- !record {model: sale.order, id: sale_free_delivery_charges}: partner_id: base.res_partner_7 partner_invoice_id: base.res_partner_address_13 @@ -57,7 +57,7 @@ order_policy: 'manual' order_line: - name: 'Service on demand' - product_id: product.product_product_consultant + product_id: product.product_product_1 product_uom_qty: 24 product_uos_qty: 24 product_uom: product.product_uom_hour diff --git a/addons/hr_timesheet/__openerp__.py b/addons/hr_timesheet/__openerp__.py index 62f0bec6009..3ba4eead94e 100644 --- a/addons/hr_timesheet/__openerp__.py +++ b/addons/hr_timesheet/__openerp__.py @@ -37,7 +37,6 @@ up a management by affair. ], 'test': [ '../account/test/account_minimal_test.xml', - 'test/hr_timesheet_data.xml', 'test/hr_timesheet_users.yml', ], 'installable': True, diff --git a/addons/hr_timesheet/hr_timesheet.py b/addons/hr_timesheet/hr_timesheet.py index a71dbd8b95b..d6687976657 100644 --- a/addons/hr_timesheet/hr_timesheet.py +++ b/addons/hr_timesheet/hr_timesheet.py @@ -14,12 +14,7 @@ class HrEmployee(models.Model): # We need the "or ..." because we need an empty recordset of the right type, 'False' is not enough. return self.env.ref('hr_timesheet.analytic_journal', raise_if_not_found=False) or self.env['account.analytic.journal'] - @api.model - def _get_default_employee_product(self): - # We need the "or ..." because we need an empty recordset of the right type, 'False' is not enough. - return self.env.ref('product.product_product_consultant', raise_if_not_found=False) or self.env['product.product'] - - product_id = fields.Many2one('product.product', 'Product', help="If you want to reinvoice working time of employees, link this employee to a service to determinate the cost price of the job.", default=_get_default_employee_product) + product_id = fields.Many2one('product.product', 'Product', help="If you want to reinvoice working time of employees, link this employee to a service to determinate the cost price of the job.") journal_id = fields.Many2one('account.analytic.journal', 'Analytic Journal', default=_get_default_analytic_journal) uom_id = fields.Many2one('product.uom', related='product_id.uom_id', string='Unit of Measure', store=True, readonly=True) @@ -48,7 +43,7 @@ class account_analytic_line(models.Model): if emp and emp.product_id.id: return emp.product_id.id else: - raise exceptions.ValidationError("This user or employee is not associated to a valid Product") + return None @api.model def _get_employee_unit(self, user_id=None): @@ -56,7 +51,7 @@ class account_analytic_line(models.Model): if emp and emp.product_id.uom_id.id: return emp.product_id.uom_id.id else: - raise exceptions.ValidationError("This user or employee is not associated to a Product with a valid Amount Type") + return None @api.model def _get_general_account(self, user_id=None): @@ -64,7 +59,7 @@ class account_analytic_line(models.Model): if emp and emp.product_id.categ_id.property_account_expense_categ_id.id: return emp.product_id.categ_id.property_account_expense_categ_id.id else: - raise exceptions.ValidationError("This user or employee is not associated to a Product with a valid Financial Account") + return None @api.model def _get_analytic_journal(self, user_id=None): @@ -72,24 +67,12 @@ class account_analytic_line(models.Model): if emp and emp.journal_id.id: return emp.journal_id.id else: - raise exceptions.ValidationError("This user or employee is not associated to a valid Journal ID") + journal = self.env['account.analytic.journal'].search([('type', '=', 'general')], limit=1) - @api.one - @api.constrains('user_id') - def check_user_id(self): - if self.is_timesheet: - emp = self.env['hr.employee'].search([('user_id', '=', self.user_id.id)], limit=1) - if not emp: - raise exceptions.ValidationError("There is no employee defined for user " + self.user_id.name) + if journal: + return journal.id else: - if not emp.journal_id.id: - raise exceptions.ValidationError("The employee " + emp.name + " is not associated to a valid Analytic Journal. Please define one for him or select another user.") - elif not emp.product_id: - raise exceptions.ValidationError("The employee " + emp.name + " is not associated to a valid Product. Please define one for him or select another user.") - elif not emp.product_id.uom_id.id: - raise exceptions.ValidationError("The employee " + emp.name + " is not associated to a valid Product Unit of Measure. Please define one for him or select another user.") - elif not emp.product_id.categ_id.property_account_expense_categ_id.id: - raise exceptions.ValidationError("The employee " + emp.name + " is not associated to a valid Financial Account. Please define one for him or select another user.") + return None @api.onchange('user_id') def V8_on_change_user_id(self): @@ -112,7 +95,7 @@ class account_analytic_line(models.Model): def on_change_unit_amount(self, cr, uid, id, prod_id, unit_amount, company_id, unit=False, journal_id=False, context=None): res = {'value': {}} - if prod_id and unit_amount: + if unit_amount: # find company company_id = self.pool.get('res.company')._company_default_get(cr, uid, 'account.analytic.line', context=context) r = super(account_analytic_line, self).on_change_unit_amount(cr, uid, id, prod_id, unit_amount, company_id, unit, journal_id, context=context) diff --git a/addons/hr_timesheet/hr_timesheet_data.xml b/addons/hr_timesheet/hr_timesheet_data.xml index 4fb03a7211e..35d6bfb0185 100644 --- a/addons/hr_timesheet/hr_timesheet_data.xml +++ b/addons/hr_timesheet/hr_timesheet_data.xml @@ -9,18 +9,5 @@ - - - True - 75.0 - 30.0 - - - Service - - service - - - diff --git a/addons/hr_timesheet/hr_timesheet_demo.xml b/addons/hr_timesheet/hr_timesheet_demo.xml index b512038e8da..faec6e306ca 100644 --- a/addons/hr_timesheet/hr_timesheet_demo.xml +++ b/addons/hr_timesheet/hr_timesheet_demo.xml @@ -1,15 +1,12 @@ - - - - + - + @@ -25,10 +22,5 @@ True - - - - - diff --git a/addons/hr_timesheet/hr_timesheet_demo.yml b/addons/hr_timesheet/hr_timesheet_demo.yml index 011a302c135..530df19cf9e 100644 --- a/addons/hr_timesheet/hr_timesheet_demo.yml +++ b/addons/hr_timesheet/hr_timesheet_demo.yml @@ -10,7 +10,7 @@ 'user_id': ref('base.user_root'), 'date': time.strftime('%Y-%m-%d'), 'unit_amount': 2.00, - 'product_id': ref('product.product_product_consultant'), + 'product_id': ref('product.product_product_1'), 'product_uom_id': ref('product.product_uom_hour'), 'account_id': ref('analytic.analytic_administratif'), 'amount': -60.00, @@ -23,7 +23,7 @@ 'user_id': ref('base.user_root'), 'date': time.strftime('%Y-%m-%d'), 'unit_amount': 1.00, - 'product_id': ref('product.product_product_consultant'), + 'product_id': ref('product.product_product_1'), 'product_uom_id': ref('product.product_uom_hour'), 'account_id': ref('analytic.analytic_administratif'), 'amount': -30.00, @@ -36,7 +36,7 @@ 'user_id': ref('base.user_root'), 'date': time.strftime('%Y-%m-%d'), 'unit_amount': 3.00, - 'product_id': ref('product.product_product_consultant'), + 'product_id': ref('product.product_product_1'), 'product_uom_id': ref('product.product_uom_hour'), 'account_id': ref('analytic.analytic_administratif'), 'amount': -90.00, @@ -49,7 +49,7 @@ 'user_id': ref('base.user_root'), 'date': time.strftime('%Y-%m-%d'), 'unit_amount': 1.00, - 'product_id': ref('product.product_product_consultant'), + 'product_id': ref('product.product_product_1'), 'product_uom_id': ref('product.product_uom_hour'), 'account_id': ref('analytic.analytic_administratif'), 'amount': -30.00, @@ -62,7 +62,7 @@ 'user_id': ref('base.user_root'), 'date': time.strftime('%Y-%m-%d'), 'unit_amount': 1.00, - 'product_id': ref('product.product_product_consultant'), + 'product_id': ref('product.product_product_1'), 'product_uom_id': ref('product.product_uom_hour'), 'account_id': ref('analytic.analytic_administratif'), 'amount': -30.00, diff --git a/addons/hr_timesheet/hr_timesheet_view.xml b/addons/hr_timesheet/hr_timesheet_view.xml index 1fa91bc1828..cd3a3f0b91b 100644 --- a/addons/hr_timesheet/hr_timesheet_view.xml +++ b/addons/hr_timesheet/hr_timesheet_view.xml @@ -6,7 +6,7 @@ account.analytic.line.tree account.analytic.line - + @@ -17,7 +17,7 @@ - + @@ -43,7 +43,7 @@ - + -