[IMP] sale, sale_timesheet: use untaxed amount inv/to inv

Since the 2 fields 'untaxed_amount_to_invoice' and
'untaxed_amount_invoiced' are reintroced
we can now use them in sale report, and in profitability report when
selling time. They will
be used in the project overview, solving the wrong amount in that view.

Task #1857652
This commit is contained in:
jem-odoo
2018-08-02 16:12:39 +02:00
parent a9658d5bf5
commit 17d0de306e
3 changed files with 10 additions and 7 deletions
+4 -4
View File
@@ -26,8 +26,8 @@ class SaleReport(models.Model):
user_id = fields.Many2one('res.users', 'Salesperson', readonly=True)
price_total = fields.Float('Total', readonly=True)
price_subtotal = fields.Float('Untaxed Total', readonly=True)
amount_to_invoice = fields.Float('Amount To Invoice', readonly=True)
amount_invoiced = fields.Float('Amount Invoiced', readonly=True)
untaxed_amount_to_invoice = fields.Float('Untaxed Amount To Invoice', readonly=True)
untaxed_amount_invoiced = fields.Float('Untaxed Amount Invoiced', readonly=True)
product_tmpl_id = fields.Many2one('product.template', 'Product Template', readonly=True)
categ_id = fields.Many2one('product.category', 'Product Category', readonly=True)
nbr = fields.Integer('# of Lines', readonly=True)
@@ -59,8 +59,8 @@ class SaleReport(models.Model):
sum(l.qty_to_invoice / u.factor * u2.factor) as qty_to_invoice,
sum(l.price_total / COALESCE(cr.rate, 1.0)) as price_total,
sum(l.price_subtotal / COALESCE(cr.rate, 1.0)) as price_subtotal,
sum(l.price_reduce * l.qty_to_invoice / COALESCE(cr.rate, 1.0)) as amount_to_invoice,
sum(l.price_reduce * l.qty_invoiced / COALESCE(cr.rate, 1.0)) as amount_invoiced,
sum(l.untaxed_amount_to_invoice / COALESCE(cr.rate, 1.0)) as untaxed_amount_to_invoice,
sum(l.untaxed_amount_invoiced / COALESCE(cr.rate, 1.0)) as untaxed_amount_invoiced,
count(*) as nbr,
s.name as name,
s.date_order as date,
@@ -51,7 +51,7 @@ class ProfitabilityAnalysis(models.Model):
SOL.product_id AS product_id,
SOL.qty_delivered_method AS sale_qty_delivered_method,
CASE
WHEN SOL.qty_delivered_method = 'analytic' THEN (SOL.price_reduce / COALESCE(CR.rate, 1.0)) * SOL.qty_to_invoice
WHEN SOL.qty_delivered_method = 'analytic' THEN (SOL.untaxed_amount_to_invoice / COALESCE(CR.rate, 1.0))
ELSE 0.0
END AS expense_amount_untaxed_to_invoice,
CASE
@@ -65,11 +65,11 @@ class ProfitabilityAnalysis(models.Model):
ELSE 0.0
END AS expense_amount_untaxed_invoiced,
CASE
WHEN SOL.qty_delivered_method = 'timesheet' THEN (SOL.price_reduce / COALESCE(CR.rate, 1.0)) * SOL.qty_to_invoice
WHEN SOL.qty_delivered_method = 'timesheet' THEN (SOL.untaxed_amount_to_invoice / COALESCE(CR.rate, 1.0))
ELSE 0.0
END AS amount_untaxed_to_invoice,
CASE
WHEN SOL.qty_delivered_method = 'timesheet' THEN (SOL.price_reduce / COALESCE(CR.rate, 1.0)) * SOL.qty_invoiced
WHEN SOL.qty_delivered_method = 'timesheet' THEN (SOL.untaxed_amount_invoiced / COALESCE(CR.rate, 1.0))
ELSE 0.0
END AS amount_untaxed_invoiced,
COST_SUMMARY.timesheet_unit_amount AS timesheet_unit_amount,
@@ -233,11 +233,13 @@ class TestReporting(TestCommonSaleTimesheetNoChart):
action_invoice = payment.with_context(context).create_invoices()
invoice_id = action_invoice['res_id']
invoice_1 = self.env['account.invoice'].browse(invoice_id)
invoice_1.action_invoice_open()
# deliver project should now have cost and something invoiced
project_so_1_stat = self.env['project.profitability.report'].read_group([('project_id', 'in', project_so_1.ids)], ['project_id', 'amount_untaxed_to_invoice', 'amount_untaxed_invoiced', 'timesheet_unit_amount', 'timesheet_cost', 'expense_cost', 'expense_amount_untaxed_to_invoice', 'expense_amount_untaxed_invoiced'], ['project_id'])[0]
project_so_1_timesheet_cost = timesheet1.amount + timesheet3.amount + timesheet5.amount
project_so_1_timesheet_sold_unit = timesheet3.unit_amount + timesheet5.unit_amount
self.assertEqual(float_compare(project_so_1_stat['amount_untaxed_invoiced'], self.so_line_deliver_project.price_unit * project_so_1_timesheet_sold_unit, precision_rounding=rounding), 0, "The invoiced amount of the project from SO1 should only include timesheet linked to task")
self.assertTrue(float_is_zero(project_so_1_stat['amount_untaxed_to_invoice'], precision_rounding=rounding), "The amount to invoice of the project from SO1 should be 0.0")
self.assertEqual(float_compare(project_so_1_stat['timesheet_unit_amount'], project_so_1_timesheet_sold_unit + timesheet1.unit_amount, precision_rounding=rounding), 0, "The timesheet unit amount of the project from SO1 should include all timesheet in project")
@@ -285,6 +287,7 @@ class TestReporting(TestCommonSaleTimesheetNoChart):
action_invoice = payment.with_context(context).create_invoices()
invoice_id = action_invoice['res_id']
invoice_2 = self.env['account.invoice'].browse(invoice_id)
invoice_2.action_invoice_open()
# deliver project should not be impacted by the invoice of the other SO
project_so_1_stat = self.env['project.profitability.report'].read_group([('project_id', 'in', project_so_1.ids)], ['project_id', 'amount_untaxed_to_invoice', 'amount_untaxed_invoiced', 'timesheet_unit_amount', 'timesheet_cost', 'expense_cost', 'expense_amount_untaxed_to_invoice', 'expense_amount_untaxed_invoiced'], ['project_id'])[0]