summaryrefslogtreecommitdiff
path: root/addons/account/models/account_analytic_line.py
diff options
context:
space:
mode:
authorJoren Van Onder <jov@odoo.com>2015-07-14 09:24:45 +0200
committerAntony Lesuisse <al@openerp.com>2015-08-03 21:51:59 +0200
commit7b32ca8452d395578bca43c3b7efd1d3f09011cb (patch)
treecdfd460a7781db5e35007f3a911efa0577365dd1 /addons/account/models/account_analytic_line.py
parent2a528aba299bc044715c36bf6106fca4e2ea43ce (diff)
[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.
Diffstat (limited to 'addons/account/models/account_analytic_line.py')
-rw-r--r--addons/account/models/account_analytic_line.py20
1 files changed, 9 insertions, 11 deletions
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