[MOV] analytic: move uom field from account to analytic

This commit is contained in:
jem-odoo
2018-08-13 14:39:50 +02:00
parent 71bf212a21
commit 8db463d124
7 changed files with 8 additions and 21 deletions
@@ -9,7 +9,6 @@ class AccountAnalyticLine(models.Model):
_description = 'Analytic Line'
_order = 'date desc'
product_uom_id = fields.Many2one('uom.uom', string='Unit of Measure')
product_id = fields.Many2one('product.product', string='Product')
general_account_id = fields.Many2one('account.account', string='Financial Account', ondelete='restrict', readonly=True,
related='move_id.account_id', store=True, domain=[('deprecated', '=', False)],
@@ -11,9 +11,8 @@
<field name="ref"/>
<field name="partner_id"/>
</xpath>
<xpath expr="//field[@name='amount']" position="after">
<xpath expr="//field[@name='product_uom_id']" position="before">
<field name="product_id"/>
<field name="product_uom_id" class="oe_inline"/>
</xpath>
<group name="amount" position="after">
<group/> <!-- put Accounting group under Amount group -->
+1 -1
View File
@@ -5,7 +5,7 @@
'name' : 'Analytic Accounting',
'version': '1.1',
'category': 'Hidden/Dependency',
'depends' : ['base', 'decimal_precision', 'mail'],
'depends' : ['base', 'decimal_precision', 'mail', 'uom'],
'description': """
Module for defining analytic accounting object.
===============================================
@@ -177,6 +177,7 @@ class AccountAnalyticLine(models.Model):
date = fields.Date('Date', required=True, index=True, default=fields.Date.context_today)
amount = fields.Monetary('Amount', required=True, default=0.0)
unit_amount = fields.Float('Quantity', default=0.0)
product_uom_id = fields.Many2one('uom.uom', string='Unit of Measure')
account_id = fields.Many2one('account.analytic.account', 'Analytic Account', required=True, ondelete='restrict', index=True)
partner_id = fields.Many2one('res.partner', string='Partner')
user_id = fields.Many2one('res.users', string='User', default=_default_user)
@@ -289,6 +289,7 @@
<group name="amount" string="Amount">
<field name="amount"/>
<field name="unit_amount"/>
<field name="product_uom_id" class="oe_inline"/>
<field name="currency_id" invisible="1"/>
</group>
</group>
@@ -95,6 +95,10 @@ class AccountAnalyticLine(models.Model):
partner_id = self.env['project.project'].browse(vals['project_id']).partner_id.id
if partner_id:
vals['partner_id'] = partner_id
# set timesheet UoM from the employee company (employee implies uom)
if 'product_uom_id' not in vals and all([v in vals for v in ['employee_id', 'project_id']]): # project_id required to check this is timesheet flow
employee = self.env['hr.employee'].sudo().browse(vals['employee_id'])
vals['product_uom_id'] = employee.company_id.project_time_mode_id.id
return vals
@api.multi
-17
View File
@@ -52,21 +52,4 @@ class AccountAnalyticLine(models.Model):
if 'task_id' in values:
task = self.env['project.task'].sudo().browse(values['task_id'])
values['so_line'] = task.sale_line_id.id or values.get('so_line', False)
# Set product_uom_id now so delivered qty is computed in SO line
if not 'product_uom_id' in values and all([v in values for v in ['employee_id', 'project_id']]):
employee = self.env['hr.employee'].sudo().browse(values['employee_id'])
values['product_uom_id'] = employee.company_id.project_time_mode_id.id
return values
@api.multi
def _timesheet_postprocess_values(self, values):
result = super(AccountAnalyticLine, self)._timesheet_postprocess_values(values)
# (re)compute the UoM from the employee company
if any([field_name in values for field_name in ['employee_id']]):
for timesheet in self:
uom = timesheet.employee_id.company_id.project_time_mode_id
result[timesheet.id].update({
'product_uom_id': uom.id,
})
return result