Skip to content

Commit

Permalink
[ADD] make invoice_vals inheritable
Browse files Browse the repository at this point in the history
  • Loading branch information
baimont committed Jun 10, 2021
1 parent 3827600 commit ab11126
Showing 1 changed file with 74 additions and 65 deletions.
139 changes: 74 additions & 65 deletions fieldservice_isp_account/models/fsm_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,7 @@ def create_bills(self):
fpos = self.person_id.partner_id.property_account_position_id
invoice_line_vals = []
for cost in self.contractor_cost_ids:
template = cost.product_id.product_tmpl_id
accounts = template.get_product_accounts()
account = accounts["expense"]
taxes = template.supplier_taxes_id
tax_ids = fpos.map_tax(taxes)
invoice_line_vals.append(
(
0,
0,
{
"analytic_account_id": self.location_id.analytic_account_id.id,
"product_id": cost.product_id.id,
"quantity": cost.quantity,
"name": cost.product_id.display_name,
"price_unit": cost.price_unit,
"account_id": account.id,
"fsm_order_ids": [(4, self.id)],
"tax_ids": [(6, 0, tax_ids.ids)],
},
)
)
invoice_line_vals.append((0, 0, self._get_bill_line_vals(cost, fpos)))
vals = {
"partner_id": self.person_id.partner_id.id,
"type": "in_invoice",
Expand All @@ -128,6 +108,23 @@ def create_bills(self):
bill = self.env["account.move"].sudo().create(vals)
bill._recompute_tax_lines()

def _get_bill_line_vals(self, cost, fpos):
template = cost.product_id.product_tmpl_id
accounts = template.get_product_accounts()
account = accounts["expense"]
taxes = template.supplier_taxes_id
tax_ids = fpos.map_tax(taxes)
return {
"analytic_account_id": self.location_id.analytic_account_id.id,
"product_id": cost.product_id.id,
"quantity": cost.quantity,
"name": cost.product_id.display_name,
"price_unit": cost.price_unit,
"account_id": account.id,
"fsm_order_ids": [(4, self.id)],
"tax_ids": [(6, 0, tax_ids.ids)],
}

def account_confirm(self):
for order in self:
contractor = order.person_id.partner_id.supplier_rank
Expand Down Expand Up @@ -178,61 +175,23 @@ def account_create_invoice(self):

invoice_line_vals = []
for cost in self.contractor_cost_ids:
price = price_list.get_product_price(
product=cost.product_id,
quantity=cost.quantity,
partner=invoice_vals.get("partner_id"),
date=False,
uom_id=False,
)
template = cost.product_id.product_tmpl_id
accounts = template.get_product_accounts()
account = accounts["income"]
taxes = template.taxes_id
tax_ids = fpos.map_tax(taxes)
invoice_line_vals.append(
(
0,
0,
{
"product_id": cost.product_id.id,
"analytic_account_id": self.location_id.analytic_account_id.id,
"quantity": cost.quantity,
"name": cost.product_id.display_name,
"price_unit": price,
"account_id": account.id,
"fsm_order_ids": [(4, self.id)],
"tax_ids": [(6, 0, tax_ids.ids)],
},
self._get_cost_invoice_line_vals(
cost, fpos, price_list, invoice_vals
),
)
)
for line in self.employee_timesheet_ids:
price = price_list.get_product_price(
product=line.product_id,
quantity=line.unit_amount,
partner=invoice_vals.get("partner_id"),
date=False,
uom_id=False,
)
template = line.product_id.product_tmpl_id
accounts = template.get_product_accounts()
account = accounts["income"]
taxes = template.taxes_id
tax_ids = fpos.map_tax(taxes)
invoice_line_vals.append(
(
0,
0,
{
"product_id": line.product_id.id,
"analytic_account_id": line.account_id.id,
"quantity": line.unit_amount,
"name": line.name,
"price_unit": price,
"account_id": account.id,
"fsm_order_ids": [(4, self.id)],
"tax_ids": [(6, 0, tax_ids.ids)],
},
self._get_timesheet_line_invoice_line_vals(
line, fpos, price_list, invoice_vals
),
)
)

Expand All @@ -243,5 +202,55 @@ def account_create_invoice(self):
self.account_stage = "invoiced"
return invoice

def _get_cost_invoice_line_vals(self, cost, fpos, price_list, invoice_vals):
price = price_list.get_product_price(
product=cost.product_id,
quantity=cost.quantity,
partner=invoice_vals.get("partner_id"),
date=False,
uom_id=False,
)
template = cost.product_id.product_tmpl_id
accounts = template.get_product_accounts()
account = accounts["income"]
taxes = template.taxes_id
tax_ids = fpos.map_tax(taxes)
return {
"product_id": cost.product_id.id,
"analytic_account_id": self.location_id.analytic_account_id.id,
"quantity": cost.quantity,
"name": cost.product_id.display_name,
"price_unit": price,
"account_id": account.id,
"fsm_order_ids": [(4, self.id)],
"tax_ids": [(6, 0, tax_ids.ids)],
}

def _get_timesheet_line_invoice_line_vals(
self, line, fpos, price_list, invoice_vals
):
price = price_list.get_product_price(
product=line.product_id,
quantity=line.unit_amount,
partner=invoice_vals.get("partner_id"),
date=False,
uom_id=False,
)
template = line.product_id.product_tmpl_id
accounts = template.get_product_accounts()
account = accounts["income"]
taxes = template.taxes_id
tax_ids = fpos.map_tax(taxes)
return {
"product_id": line.product_id.id,
"analytic_account_id": line.account_id.id,
"quantity": line.unit_amount,
"name": line.name,
"price_unit": price,
"account_id": account.id,
"fsm_order_ids": [(4, self.id)],
"tax_ids": [(6, 0, tax_ids.ids)],
}

def account_no_invoice(self):
self.account_stage = "no"

0 comments on commit ab11126

Please sign in to comment.