[IMP] sale: rename 'project_id' into 'analytic_account_id'
Since this field is an analytic account and not a project, its name should be more explicit. This commit makes the code more understandable. Naming things correctly improve developper's sleep.
This commit is contained in:
@@ -106,9 +106,9 @@ class AccountAnalyticLine(models.Model):
|
||||
"""
|
||||
for analytic_line in self.sudo().filtered(lambda aal: not aal.so_line and aal.account_id and aal.product_id and aal.product_id.expense_policy != 'no'):
|
||||
# determine SO : first SO open linked to AA
|
||||
sale_order = self.env['sale.order'].search([('project_id', '=', analytic_line.account_id.id), ('state', '=', 'sale')], limit=1)
|
||||
sale_order = self.env['sale.order'].search([('analytic_account_id', '=', analytic_line.account_id.id), ('state', '=', 'sale')], limit=1)
|
||||
if not sale_order:
|
||||
sale_order = self.env['sale.order'].search([('project_id', '=', analytic_line.account_id.id)], limit=1)
|
||||
sale_order = self.env['sale.order'].search([('analytic_account_id', '=', analytic_line.account_id.id)], limit=1)
|
||||
if not sale_order:
|
||||
continue
|
||||
|
||||
|
||||
@@ -135,7 +135,7 @@ class SaleOrder(models.Model):
|
||||
|
||||
pricelist_id = fields.Many2one('product.pricelist', string='Pricelist', required=True, readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="Pricelist for current sales order.")
|
||||
currency_id = fields.Many2one("res.currency", related='pricelist_id.currency_id', string="Currency", readonly=True, required=True)
|
||||
project_id = fields.Many2one('account.analytic.account', 'Analytic Account', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="The analytic account related to a sales order.", copy=False)
|
||||
analytic_account_id = fields.Many2one('account.analytic.account', 'Analytic Account', readonly=True, states={'draft': [('readonly', False)], 'sent': [('readonly', False)]}, help="The analytic account related to a sales order.", copy=False, oldname='project_id')
|
||||
|
||||
order_line = fields.One2many('sale.order.line', 'order_id', string='Order Lines', states={'cancel': [('readonly', True)], 'done': [('readonly', True)]}, copy=True, auto_join=True)
|
||||
|
||||
@@ -509,7 +509,7 @@ class SaleOrder(models.Model):
|
||||
'company_id': order.company_id.id,
|
||||
'partner_id': order.partner_id.id
|
||||
})
|
||||
order.project_id = analytic
|
||||
order.analytic_account_id = analytic
|
||||
|
||||
@api.multi
|
||||
def order_lines_layouted(self):
|
||||
@@ -891,7 +891,7 @@ class SaleOrderLine(models.Model):
|
||||
'product_id': self.product_id.id or False,
|
||||
'layout_category_id': self.layout_category_id and self.layout_category_id.id or False,
|
||||
'invoice_line_tax_ids': [(6, 0, self.tax_id.ids)],
|
||||
'account_analytic_id': self.order_id.project_id.id,
|
||||
'account_analytic_id': self.order_id.analytic_account_id.id,
|
||||
'analytic_tag_ids': [(6, 0, self.analytic_tag_ids.ids)],
|
||||
}
|
||||
return res
|
||||
|
||||
@@ -42,7 +42,7 @@ class PosSaleReport(models.Model):
|
||||
rp.country_id AS country_id,
|
||||
sol.price_subtotal / COALESCE (cr.rate, 1.0) AS price_subtotal,
|
||||
(sol.product_uom_qty / u.factor * u2.factor) as product_qty,
|
||||
so.project_id AS analytic_account_id,
|
||||
so.analytic_account_id AS analytic_account_id,
|
||||
so.team_id AS team_id
|
||||
|
||||
FROM sale_order_line sol
|
||||
|
||||
@@ -71,7 +71,7 @@ class SaleReport(models.Model):
|
||||
extract(epoch from avg(date_trunc('day',s.date_order)-date_trunc('day',s.create_date)))/(24*60*60)::decimal(16,2) as delay,
|
||||
t.categ_id as categ_id,
|
||||
s.pricelist_id as pricelist_id,
|
||||
s.project_id as analytic_account_id,
|
||||
s.analytic_account_id as analytic_account_id,
|
||||
s.team_id as team_id,
|
||||
p.product_tmpl_id,
|
||||
partner.country_id as country_id,
|
||||
@@ -112,7 +112,7 @@ class SaleReport(models.Model):
|
||||
s.state,
|
||||
s.company_id,
|
||||
s.pricelist_id,
|
||||
s.project_id,
|
||||
s.analytic_account_id,
|
||||
s.team_id,
|
||||
p.product_tmpl_id,
|
||||
partner.country_id,
|
||||
|
||||
@@ -127,7 +127,7 @@ class TestSaleOrder(TestSale):
|
||||
'name': '',
|
||||
'type': 'in_invoice',
|
||||
'partner_id': inv_partner.id,
|
||||
'invoice_line_ids': [(0, 0, {'name': serv_cost.name, 'product_id': serv_cost.id, 'quantity': 2, 'uom_id': serv_cost.uom_id.id, 'price_unit': serv_cost.standard_price, 'account_analytic_id': so.project_id.id, 'account_id': account_income.id})],
|
||||
'invoice_line_ids': [(0, 0, {'name': serv_cost.name, 'product_id': serv_cost.id, 'quantity': 2, 'uom_id': serv_cost.uom_id.id, 'price_unit': serv_cost.standard_price, 'account_analytic_id': so.analytic_account_id.id, 'account_id': account_income.id})],
|
||||
'account_id': account_payable.id,
|
||||
'journal_id': journal.id,
|
||||
'currency_id': company.currency_id.id,
|
||||
|
||||
@@ -383,7 +383,7 @@
|
||||
<field name="team_id" options="{'no_create': True}"/>
|
||||
<field name="client_order_ref"/>
|
||||
<field name="company_id" options="{'no_create': True}" groups="base.group_multi_company"/>
|
||||
<field name="project_id" context="{'default_partner_id':partner_invoice_id, 'default_name':name}" attrs="{'readonly': ['|',('project_id','!=',False),('invoice_count','!=',0),('state','=','sale')]}" groups="analytic.group_analytic_accounting"/>
|
||||
<field name="analytic_account_id" context="{'default_partner_id':partner_invoice_id, 'default_name':name}" attrs="{'readonly': ['|',('analytic_account_id','!=',False),('invoice_count','!=',0),('state','=','sale')]}" groups="analytic.group_analytic_accounting"/>
|
||||
</group>
|
||||
<group name="sale_pay" string="Invoicing">
|
||||
<field name="date_order" attrs="{'invisible': [('state', 'in', ['sale', 'done', 'cancel'])]}"/>
|
||||
@@ -429,7 +429,7 @@
|
||||
<field name="partner_id" operator="child_of"/>
|
||||
<field name="user_id"/>
|
||||
<field name="team_id" string="Sales Channel"/>
|
||||
<field name="project_id"/>
|
||||
<field name="analytic_account_id"/>
|
||||
<field name="product_id"/>
|
||||
<filter string="My Orders" domain="[('user_id','=',uid)]" name="my_sale_orders_filter"/>
|
||||
<separator/>
|
||||
|
||||
@@ -107,7 +107,7 @@ class SaleAdvancePaymentInv(models.TransientModel):
|
||||
'product_id': self.product_id.id,
|
||||
'sale_line_ids': [(6, 0, [so_line.id])],
|
||||
'invoice_line_tax_ids': [(6, 0, tax_ids)],
|
||||
'account_analytic_id': order.project_id.id or False,
|
||||
'account_analytic_id': order.analytic_account_id.id or False,
|
||||
})],
|
||||
'currency_id': order.pricelist_id.currency_id.id,
|
||||
'payment_term_id': order.payment_term_id.id,
|
||||
|
||||
@@ -40,7 +40,7 @@ class TestSaleExpense(TestSale):
|
||||
exp = self.env['hr.expense'].create({
|
||||
'name': 'Air Travel',
|
||||
'product_id': prod_exp_1.id,
|
||||
'analytic_account_id': so.project_id.id,
|
||||
'analytic_account_id': so.analytic_account_id.id,
|
||||
'unit_amount': 621.54,
|
||||
'employee_id': employee.id,
|
||||
'sheet_id': sheet.id
|
||||
@@ -67,7 +67,7 @@ class TestSaleExpense(TestSale):
|
||||
exp = self.env['hr.expense'].create({
|
||||
'name': 'Car Travel',
|
||||
'product_id': prod_exp_2.id,
|
||||
'analytic_account_id': so.project_id.id,
|
||||
'analytic_account_id': so.analytic_account_id.id,
|
||||
'product_uom_id': self.env.ref('product.product_uom_km').id,
|
||||
'unit_amount': 0.15,
|
||||
'quantity': 100,
|
||||
|
||||
@@ -57,7 +57,7 @@ class AccountAnalyticLine(models.Model):
|
||||
"""
|
||||
for timesheet in self.filtered(lambda aal: not aal.so_line):
|
||||
sol = self.env['sale.order.line'].search([
|
||||
('order_id.project_id', '=', timesheet.account_id.id),
|
||||
('order_id.analytic_account_id', '=', timesheet.account_id.id),
|
||||
('state', 'in', ('sale', 'done')),
|
||||
('product_id.track_service', '=', 'timesheet'),
|
||||
('product_id.type', '=', 'service')
|
||||
|
||||
@@ -19,10 +19,10 @@ class SaleOrder(models.Model):
|
||||
project_project_id = fields.Many2one('project.project', compute='_compute_project_project_id', string='Project associated to this sale')
|
||||
|
||||
@api.multi
|
||||
@api.depends('project_id.line_ids')
|
||||
@api.depends('analytic_account_id.line_ids')
|
||||
def _compute_timesheet_ids(self):
|
||||
for order in self:
|
||||
if order.project_id:
|
||||
if order.analytic_account_id:
|
||||
order.timesheet_ids = self.env['account.analytic.line'].search(
|
||||
[('so_line', 'in', order.order_line.ids),
|
||||
('amount', '<=', 0.0),
|
||||
@@ -39,10 +39,10 @@ class SaleOrder(models.Model):
|
||||
order.tasks_count = len(order.tasks_ids)
|
||||
|
||||
@api.multi
|
||||
@api.depends('project_id.project_ids')
|
||||
@api.depends('analytic_account_id.project_ids')
|
||||
def _compute_project_project_id(self):
|
||||
for order in self:
|
||||
order.project_project_id = self.env['project.project'].search([('analytic_account_id', '=', order.project_id.id)])
|
||||
order.project_project_id = self.env['project.project'].search([('analytic_account_id', '=', order.analytic_account_id.id)])
|
||||
|
||||
@api.multi
|
||||
@api.constrains('order_line')
|
||||
@@ -175,10 +175,10 @@ class SaleOrderLine(models.Model):
|
||||
project = self.product_id.with_context(force_company=self.company_id.id).project_id
|
||||
if not project:
|
||||
# find the project corresponding to the analytic account of the sales order
|
||||
account = self.order_id.project_id
|
||||
account = self.order_id.analytic_account_id
|
||||
if not account:
|
||||
self.order_id._create_analytic_account(prefix=self.product_id.default_code or None)
|
||||
account = self.order_id.project_id
|
||||
account = self.order_id.analytic_account_id
|
||||
project = Project.search([('analytic_account_id', '=', account.id)], limit=1)
|
||||
if not project:
|
||||
project_id = account.sudo().project_create({'name': account.name})
|
||||
|
||||
Reference in New Issue
Block a user