summaryrefslogtreecommitdiff
path: root/addons/sale_mrp
diff options
context:
space:
mode:
authorLaurent Smet <las@odoo.com>2019-05-29 13:35:09 +0000
committerqdp-odoo <qdp@odoo.com>2019-06-28 11:52:55 +0000
commitbeaa30a3d1843de43a45f419bfbc1bfa7613a920 (patch)
tree00e62f6861eb15b3735fe032b849fd3e6150868c /addons/sale_mrp
parent0bd61b5245e475825fdeb33fb7b9ddb4f378c657 (diff)
[IMP/REF] accounting-pocalypse yeaaahh
This commit merges the following models * account.invoice and account.move * account.invoice.line and account.move.line * account.voucher and account.move * account.voucher.line and account.move.line It was the opportunity for a big cleanup of the code, so it also restructures the whole account module, its different models/fields, the tests etc. for a better world and a better code readability. ==== Rationale ==== The rationale of this huge change is that we want journal entries / invoices to be easily edited, and changes reflected in the other model. It's a HUGE feature and very strategic for the fiduciary companies. For example, changing the account of a journal entry needs to be automatically reflected on the related invoice. The same reasoning applies to sale/purchase vouchers. ==== Changes made in features ===== When creating an invoice, you are now creating a journal entry directly. --> The object account.invoice no longer exists. In the same fashion when creating an invoice line, you're now adding journal items directly in the journal entry representing the invoice. If this invoice line has some tax, it may create additional journal items as well. --> The models account.invoice.line & account.invoice.tax no longer exist Identically, when creating a sale/purchase receipt with its lines, you are now creating a journal entry directly and there's no more usability difference between encoding a receipt or an invoice. --> The object account.voucher no longer exists. --> The object account.voucher.line no longer exists. --> The whole account_voucher module no longer exists. Positive side-effects coming from these changes are * draft invoices/bills/sale or purchase receipts now create a draft accounting entry. Validate these objects now simply post its journal entry. That means that draft invoices/bills/sale or purchase receipt can straightforwardly be included in reporting or budgets. * opening a journal entry in form view will now always open the correct view: if it's a sale/purchase journal entry we will have a customer invoice/vendor bill view or a sale/purchase receipt view, whatever the menu we're coming from. * code & business logic simplification. It is also condensed in a single place instead of being partially duplicated on invoices, vouchers and journal entries. There should be no feature loss, except the one allowing to group multiple journal items together based on the same product during the invoice validation. ==== Changes made in models ===== * account.invoice: model removed. Instead, now use account.move with following mapping field (account.invoice) field (account.move) ----------------------- -------------------- name invoice_payment_ref number name reference ref comment narration user_id invoice_user_id amount_ total_company_signed amount_total_signed residual amount_residual state state + invoice_payment_state /!\ selection changed date_invoice invoice_date date_due invoice_date_due sent invoice_sent origin invoice_origin payment_term_id invoice_payment_term_id partner_bank_id invoice_partner_bank_id incoterm_id invoice_incoterm_id vendor_bill_id invoice_vendor_bill_id source_email invoice_source_email vendor_display_name invoice_vendor_display_name invoice_icon invoice_vendor_icon cash_rounding_id invoice_cash_rounding_id sequence_number_next invoice_sequence_number_next sequence_number_next_prefix invoice_sequence_number_next_prefix 'invoices' subset of account.move can be accessed by using the selection field 'type' or one of the many helpers like is_invoice() * account.move: now has a valid state 'cancel' that has to be excluded from all business logic * account.move: field 'amount' renamed into 'amount_total' * account.move: field 'reverse_entry_id' renamed into 'reversed_entry_id' * account.move.line: now has a field 'display_type' that has to be excluded from all business logic, in order to support invoice layouting * account.invoice.line: model removed. Instead, now use account.move.line with following mapping field (account.invoice.line) field (account.move.line) ---------------------------- ------------------------- invoice_id move_id uom_id product_uom_id invoice_line_tax_ids tax_ids account_analytic_id analytic_account_id 'invoice lines' subset of all account.move.line from a journal entry can be accessed by using the boolean field 'exclude_from_invoice_tab' * account.invoice.tax: model removed. Instead, now use account.move.line with following mapping field (account.invoice.tax) field (account.move.line) --------------------------- ------------------------- invoice_id move_id account_analytic_id analytic_account_id amount price_unit base tax_base_amount 'tax lines' subset of all account.move.line from a journal entry can be accessed by using the relational field 'tax_line_id' * account.invoice.confirm: model removed. Instead, now use the 'post()' function of account.move * account.invoice.refund: model removed. Instead, now use account.move.reversal to reverse the entries with the same options as we had for invoices * account.voucher: model removed. Instead, now use account.move of type in ['out_receipt', 'in_receipt] * account.voucher.line: model removed. Instead, now use account.move.line ==== Changes made in functions ==== * on account.move, method _run_post_draft_to_post() renamed into _autopost_draft_entries() * on account.move, method action_account_invoice_payment() renamed into action_invoice_register_payment() * on account.move, method action_invoice_reconcile_to_check() renamed into action_open_matching_suspense_moves() * on account.move, method _get_domain_edition_mode_available() renamed into _get_domain_matching_supsense_moves() * on account.move, method _get_intrastat_country_id() renamed into _get_invoice_intrastat_country_id() * on account.move.line, method _get_domain_for_edition_mode() renamed into _get_suspense_moves_domain() * in account.bank.statement, contextual key 'edition_mode' renamed into 'suspense_moves_mode' Was task 1917430
Diffstat (limited to 'addons/sale_mrp')
-rw-r--r--addons/sale_mrp/models/__init__.py1
-rw-r--r--addons/sale_mrp/models/account_move.py35
-rw-r--r--addons/sale_mrp/models/sale_mrp.py33
-rw-r--r--addons/sale_mrp/tests/test_sale_mrp_flow.py24
4 files changed, 53 insertions, 40 deletions
diff --git a/addons/sale_mrp/models/__init__.py b/addons/sale_mrp/models/__init__.py
index 75e0d652578..9a9609e5400 100644
--- a/addons/sale_mrp/models/__init__.py
+++ b/addons/sale_mrp/models/__init__.py
@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import sale_mrp
+from . import account_move
diff --git a/addons/sale_mrp/models/account_move.py b/addons/sale_mrp/models/account_move.py
new file mode 100644
index 00000000000..a1ff4ff9c2b
--- /dev/null
+++ b/addons/sale_mrp/models/account_move.py
@@ -0,0 +1,35 @@
+# -*- coding: utf-8 -*-
+from odoo import models
+
+
+class AccountMoveLine(models.Model):
+ # TDE FIXME: what is this code ??
+ _inherit = "account.move.line"
+
+ def _stock_account_get_anglo_saxon_price_unit(self):
+ price_unit = super(AccountMoveLine, self)._stock_account_get_anglo_saxon_price_unit()
+ # in case of anglo saxon with a product configured as invoiced based on delivery, with perpetual
+ # valuation and real price costing method, we must find the real price for the cost of good sold
+ if self.product_id.invoice_policy == "delivery":
+ for s_line in self.sale_line_ids:
+ # qtys already invoiced
+ qty_done = sum([x.product_uom_id._compute_quantity(x.quantity, x.product_id.uom_id) for x in s_line.invoice_lines if x.move_id.state == 'posted'])
+ quantity = self.product_uom_id._compute_quantity(self.quantity, self.product_id.uom_id)
+ # Put moves in fixed order by date executed
+ moves = s_line.move_ids.sorted(lambda x: x.date)
+ # Go through all the moves and do nothing until you get to qty_done
+ # Beyond qty_done we need to calculate the average of the price_unit
+ # on the moves we encounter.
+ bom = s_line.product_id.product_tmpl_id.bom_ids and s_line.product_id.product_tmpl_id.bom_ids[0]
+ if bom.type == 'phantom':
+ average_price_unit = 0
+ components = s_line._get_bom_component_qty(bom)
+ for product_id in components:
+ factor = components[product_id]['qty']
+ prod_moves = [m for m in moves if m.product_id.id == product_id]
+ prod_qty_done = factor * qty_done
+ prod_quantity = factor * quantity
+ average_price_unit += factor * self._compute_average_price(prod_qty_done, prod_quantity, prod_moves)
+ price_unit = average_price_unit or price_unit
+ price_unit = self.product_id.uom_id._compute_price(price_unit, self.product_uom_id)
+ return price_unit
diff --git a/addons/sale_mrp/models/sale_mrp.py b/addons/sale_mrp/models/sale_mrp.py
index d80fdf068a7..f63519c0f72 100644
--- a/addons/sale_mrp/models/sale_mrp.py
+++ b/addons/sale_mrp/models/sale_mrp.py
@@ -101,36 +101,3 @@ class SaleOrderLine(models.Model):
if bom and 'previous_product_uom_qty' in self.env.context:
return previous_product_uom_qty and previous_product_uom_qty.get(self.id, 0.0)
return super(SaleOrderLine, self)._get_qty_procurement(previous_product_uom_qty=previous_product_uom_qty)
-
-
-class AccountInvoiceLine(models.Model):
- # TDE FIXME: what is this code ??
- _inherit = "account.invoice.line"
-
- def _get_anglo_saxon_price_unit(self):
- price_unit = super(AccountInvoiceLine, self)._get_anglo_saxon_price_unit()
- # in case of anglo saxon with a product configured as invoiced based on delivery, with perpetual
- # valuation and real price costing method, we must find the real price for the cost of good sold
- if self.product_id.invoice_policy == "delivery":
- for s_line in self.sale_line_ids:
- # qtys already invoiced
- qty_done = sum([x.uom_id._compute_quantity(x.quantity, x.product_id.uom_id) for x in s_line.invoice_lines if x.invoice_id.state in ('open', 'in_payment', 'paid')])
- quantity = self.uom_id._compute_quantity(self.quantity, self.product_id.uom_id)
- # Put moves in fixed order by date executed
- moves = s_line.move_ids.sorted(lambda x: x.date)
- # Go through all the moves and do nothing until you get to qty_done
- # Beyond qty_done we need to calculate the average of the price_unit
- # on the moves we encounter.
- bom = s_line.product_id.product_tmpl_id.bom_ids and s_line.product_id.product_tmpl_id.bom_ids[0]
- if bom.type == 'phantom':
- average_price_unit = 0
- components = s_line._get_bom_component_qty(bom)
- for product_id in components:
- factor = components[product_id]['qty']
- prod_moves = [m for m in moves if m.product_id.id == product_id]
- prod_qty_done = factor * qty_done
- prod_quantity = factor * quantity
- average_price_unit += factor * self._compute_average_price(prod_qty_done, prod_quantity, prod_moves)
- price_unit = average_price_unit or price_unit
- price_unit = self.product_id.uom_id._compute_price(price_unit, self.uom_id)
- return price_unit
diff --git a/addons/sale_mrp/tests/test_sale_mrp_flow.py b/addons/sale_mrp/tests/test_sale_mrp_flow.py
index 4f4c2a35061..bafa2a17882 100644
--- a/addons/sale_mrp/tests/test_sale_mrp_flow.py
+++ b/addons/sale_mrp/tests/test_sale_mrp_flow.py
@@ -561,6 +561,7 @@ class TestSaleMrpFlow(common.SavepointCase):
# These products are in the Test category
# The bom consists of 2 component1 and 1 component2
# The invoice policy of the finished product is based on delivered quantities
+ self.env.company.currency_id = self.env.ref('base.USD')
self.uom_unit = self.UoM.create({
'name': 'Test-Unit',
'category_id': self.categ_unit.id,
@@ -571,7 +572,7 @@ class TestSaleMrpFlow(common.SavepointCase):
self.company.anglo_saxon_accounting = True
self.partner = self.env.ref('base.res_partner_1')
self.category = self.env.ref('product.product_category_1').copy({'name': 'Test category','property_valuation': 'real_time', 'property_cost_method': 'fifo'})
- account_type = self.env['account.account.type'].create({'name': 'RCV type', 'type': 'receivable'})
+ account_type = self.env['account.account.type'].create({'name': 'RCV type', 'type': 'other'})
self.account_receiv = self.env['account.account'].create({'name': 'Receivable', 'code': 'RCV00' , 'user_type_id': account_type.id, 'reconcile': True})
account_expense = self.env['account.account'].create({'name': 'Expense', 'code': 'EXP00' , 'user_type_id': account_type.id, 'reconcile': True})
account_output = self.env['account.account'].create({'name': 'Output', 'code': 'OUT00' , 'user_type_id': account_type.id, 'reconcile': True})
@@ -632,7 +633,13 @@ class TestSaleMrpFlow(common.SavepointCase):
'partner_id': self.partner.id,
'partner_invoice_id': self.partner.id,
'partner_shipping_id': self.partner.id,
- 'order_line': [(0, 0, {'name': self.finished_product.name, 'product_id': self.finished_product.id, 'product_uom_qty': 3, 'product_uom': self.finished_product.uom_id.id, 'price_unit': self.finished_product.list_price})],
+ 'order_line': [(0, 0, {
+ 'name': self.finished_product.name,
+ 'product_id': self.finished_product.id,
+ 'product_uom_qty': 3,
+ 'product_uom': self.finished_product.uom_id.id,
+ 'price_unit': self.finished_product.list_price
+ })],
'pricelist_id': self.env.ref('product.list0').id,
'company_id': self.company.id,
}
@@ -650,11 +657,14 @@ class TestSaleMrpFlow(common.SavepointCase):
self.so._create_invoices()
self.invoice = self.so.invoice_ids
# Changed the invoiced quantity of the finished product to 2
- self.invoice.invoice_line_ids.write({'quantity': 2.0})
- self.invoice.action_invoice_open()
- aml = self.invoice.move_id.line_ids
- aml_expense = aml.filtered(lambda l: l.account_id.id == account_expense.id)
- aml_output = aml.filtered(lambda l: l.account_id.id == account_output.id)
+ move_form = Form(self.invoice)
+ with move_form.invoice_line_ids.edit(0) as line_form:
+ line_form.quantity = 2.0
+ self.invoice = move_form.save()
+ self.invoice.post()
+ aml = self.invoice.line_ids
+ aml_expense = aml.filtered(lambda l: l.is_anglo_saxon_line and l.debit > 0)
+ aml_output = aml.filtered(lambda l: l.is_anglo_saxon_line and l.credit > 0)
# Check that the cost of Good Sold entries are equal to 2* (2 * 20 + 1 * 10) = 100
self.assertEqual(aml_expense.debit, 100, "Cost of Good Sold entry missing or mismatching")
self.assertEqual(aml_output.credit, 100, "Cost of Good Sold entry missing or mismatching")