From c4d71d7d24bd1aca38123b338b5af04e2e602901 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9my=20Voet=20=28ryv=29?= Date: Tue, 28 Jan 2020 13:29:31 +0000 Subject: [PATCH] [REM] stock_account: clean import/condition/dead-code For the stock_account module: - Remove unused import - Remove deadcode, unused _anglo_saxon_sale_move_lines method and useless 'continue' keyword - Fix duplicate name test (test_average_perpetual_8 defines twice) - Make comments flake8 compliant task-2123752 --- addons/stock_account/models/account_move.py | 2 +- addons/stock_account/models/product.py | 61 +------------------ addons/stock_account/models/stock_move.py | 10 +-- .../tests/test_stockvaluation.py | 2 +- 4 files changed, 8 insertions(+), 67 deletions(-) diff --git a/addons/stock_account/models/account_move.py b/addons/stock_account/models/account_move.py index 8a9dd971f33..c9e0676b433 100644 --- a/addons/stock_account/models/account_move.py +++ b/addons/stock_account/models/account_move.py @@ -1,6 +1,6 @@ # -*- coding: utf-8 -*- -from odoo import fields, models, api, _ +from odoo import fields, models class AccountMove(models.Model): diff --git a/addons/stock_account/models/product.py b/addons/stock_account/models/product.py index 063f2378039..f4c087bb0d1 100644 --- a/addons/stock_account/models/product.py +++ b/addons/stock_account/models/product.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models, tools, _ +from odoo import api, fields, models, _ from odoo.exceptions import UserError from odoo.tools import float_is_zero from odoo.exceptions import ValidationError @@ -38,7 +38,7 @@ class ProductTemplate(models.Model): # Empty out the stock with the current cost method. description = _("Due to a change of product category (from %s to %s), the costing method\ has changed for product template %s: from %s to %s.") %\ - (product_template.categ_id.display_name, new_product_category.display_name, \ + (product_template.categ_id.display_name, new_product_category.display_name, product_template.display_name, product_template.cost_method, new_product_category.property_cost_method) out_svl_vals_list, products_orig_quantity_svl, products = Product\ ._svl_empty_stock(description, product_template=product_template) @@ -164,7 +164,7 @@ class ProductProduct(models.Model): # Quantity is negative for out valuation layers. quantity = -1 * quantity vals = { - 'product_id' : self.id, + 'product_id': self.id, 'value': quantity * self.standard_price, 'unit_cost': self.standard_price, 'quantity': quantity, @@ -533,61 +533,6 @@ class ProductProduct(models.Model): # ------------------------------------------------------------------------- # Anglo saxon helpers # ------------------------------------------------------------------------- - @api.model - def _anglo_saxon_sale_move_lines(self, name, product, uom, qty, price_unit, currency=False, amount_currency=False, fiscal_position=False, account_analytic=False, analytic_tags=False): - """Prepare dicts describing new journal COGS journal items for a product sale. - - Returns a dict that should be passed to `_convert_prepared_anglosaxon_line()` to - obtain the creation value for the new journal items. - - :param Model product: a product.product record of the product being sold - :param Model uom: a product.uom record of the UoM of the sale line - :param Integer qty: quantity of the product being sold - :param Integer price_unit: unit price of the product being sold - :param Model currency: a res.currency record from the order of the product being sold - :param Interger amount_currency: unit price in the currency from the order of the product being sold - :param Model fiscal_position: a account.fiscal.position record from the order of the product being sold - :param Model account_analytic: a account.account.analytic record from the line of the product being sold - """ - - if product.type == 'product' and product.valuation == 'real_time': - accounts = product.product_tmpl_id.get_product_accounts(fiscal_pos=fiscal_position) - # debit account dacc will be the output account - dacc = accounts['stock_output'].id - # credit account cacc will be the expense account - cacc = accounts['expense'].id - if dacc and cacc: - return [ - { - 'type': 'src', - 'name': name[:64], - 'price_unit': price_unit, - 'quantity': qty, - 'price': price_unit * qty, - 'currency_id': currency and currency.id, - 'amount_currency': amount_currency, - 'account_id': dacc, - 'product_id': product.id, - 'uom_id': uom.id, - }, - - { - 'type': 'src', - 'name': name[:64], - 'price_unit': price_unit, - 'quantity': qty, - 'price': -1 * price_unit * qty, - 'currency_id': currency and currency.id, - 'amount_currency': -1 * amount_currency, - 'account_id': cacc, - 'product_id': product.id, - 'uom_id': uom.id, - 'account_analytic_id': account_analytic and account_analytic.id, - 'analytic_tag_ids': analytic_tags and analytic_tags.ids and [(6, 0, analytic_tags.ids)] or False, - }, - ] - return [] - def _stock_account_get_anglo_saxon_price_unit(self, uom=False): price = self.standard_price if not self or not uom or self.uom_id.id == uom.id: diff --git a/addons/stock_account/models/stock_move.py b/addons/stock_account/models/stock_move.py index c6e10bf345d..48937345bed 100644 --- a/addons/stock_account/models/stock_move.py +++ b/addons/stock_account/models/stock_move.py @@ -5,7 +5,7 @@ from collections import defaultdict from odoo import api, fields, models, _ from odoo.exceptions import UserError -from odoo.tools import float_compare, float_round, float_is_zero +from odoo.tools import float_is_zero import logging _logger = logging.getLogger(__name__) @@ -240,7 +240,6 @@ class StockMove(models.Model): for valued_type in self._get_valued_types(): if getattr(move, '_is_%s' % valued_type)(): valued_moves[valued_type] |= move - continue # AVCO application valued_moves['in'].product_price_update_before_done() @@ -252,7 +251,6 @@ class StockMove(models.Model): for valued_type in self._get_valued_types(): if getattr(move, '_is_%s' % valued_type)(): valued_moves[valued_type] |= move - continue stock_valuation_layers = self.env['stock.valuation.layer'].sudo() # Create the valuation layers in batch by calling `moves._create_valued_type_svl`. @@ -261,8 +259,6 @@ class StockMove(models.Model): if todo_valued_moves: todo_valued_moves._sanity_check_for_valuation() stock_valuation_layers |= getattr(todo_valued_moves, '_create_%s_svl' % valued_type)() - continue - for svl in stock_valuation_layers: if not svl.product_id.valuation == 'real_time': @@ -509,10 +505,10 @@ class StockMove(models.Model): self.with_company(self.company_id)._create_account_move_line(acc_dest, acc_valuation, journal_id, qty, description, svl_id, cost) if self.company_id.anglo_saxon_accounting: - #eventually reconcile together the invoice and valuation accounting entries on the stock interim accounts + # Eventually reconcile together the invoice and valuation accounting entries on the stock interim accounts self._get_related_invoices()._stock_account_anglo_saxon_reconcile_valuation(product=self.product_id) - def _get_related_invoices(self): # To be overridden in purchase and sale_stock + def _get_related_invoices(self): # To be overridden in purchase and sale_stock """ This method is overrided in both purchase and sale_stock modules to adapt to the way they mix stock moves with invoices. """ diff --git a/addons/stock_account/tests/test_stockvaluation.py b/addons/stock_account/tests/test_stockvaluation.py index 3f986835190..0db6ec7e952 100644 --- a/addons/stock_account/tests/test_stockvaluation.py +++ b/addons/stock_account/tests/test_stockvaluation.py @@ -2433,7 +2433,7 @@ class TestStockValuation(SavepointCase): self.assertAlmostEqual(self.product1.standard_price, 10.0) - def test_average_perpetual_8(self): + def test_average_perpetual_9(self): """ When a product has an available quantity of -5, edit an incoming shipment and increase the received quantity by 5 units. """