diff --git a/account_invoice_margin/__init__.py b/account_invoice_margin/__init__.py index 34f74ab..65739c5 100644 --- a/account_invoice_margin/__init__.py +++ b/account_invoice_margin/__init__.py @@ -1,4 +1,2 @@ -# -*- coding: utf-8 -*- - from . import account_invoice from . import account_invoice_report diff --git a/account_invoice_margin/__manifest__.py b/account_invoice_margin/__manifest__.py index 356b300..21a5395 100644 --- a/account_invoice_margin/__manifest__.py +++ b/account_invoice_margin/__manifest__.py @@ -1,11 +1,11 @@ -# -*- coding: utf-8 -*- -# © 2015-2017 Akretion (http://www.akretion.com) +# Copyright 2015-2019 Akretion France (http://www.akretion.com) # @author Alexis de Lattre +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Account Invoice Margin', - 'version': '10.0.1.0.0', - 'category': 'Accounting & Finance', + 'version': '12.0.1.0.0', + 'category': 'Invoicing Management', 'license': 'AGPL-3', 'summary': 'Copy standard price on invoice line and compute margins', 'description': """ diff --git a/account_invoice_margin/account_invoice.py b/account_invoice_margin/account_invoice.py index 1c5a0dc..e42cac9 100644 --- a/account_invoice_margin/account_invoice.py +++ b/account_invoice_margin/account_invoice.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- -# © 2015-2017 Akretion (http://www.akretion.com) +# Copyright 2015-2019 Akretion France (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from odoo import api, fields, models import odoo.addons.decimal_precision as dp @@ -48,16 +47,18 @@ class AccountInvoiceLine(models.Model): # it works in _get_current_rate # even if we set date = False in context # standard_price_inv_cur is in the UoM of the invoice line + date = inv._get_currency_rate_date() or\ + fields.Date.context_today(self) + company = inv.company_id + company_currency = company.currency_id standard_price_inv_cur =\ - inv.company_id.currency_id.with_context( - date=inv.date_invoice).compute( - il.standard_price_company_currency, - inv.currency_id) + company_currency._convert( + il.standard_price_company_currency, + inv.currency_id, company, date) margin_inv_cur =\ il.price_subtotal - il.quantity * standard_price_inv_cur - margin_comp_cur = inv.currency_id.with_context( - date=inv.date_invoice).compute( - margin_inv_cur, inv.company_id.currency_id) + margin_comp_cur = inv.currency_id._convert( + margin_inv_cur, company_currency, company, date) if il.price_subtotal: margin_rate = 100 * margin_inv_cur / il.price_subtotal # for a refund, margin should be negative @@ -83,13 +84,12 @@ class AccountInvoiceLine(models.Model): std_price = pp.standard_price inv_uom_id = vals.get('uom_id') if inv_uom_id and inv_uom_id != pp.uom_id.id: - inv_uom = self.env['product.uom'].browse(inv_uom_id) + inv_uom = self.env['uom.uom'].browse(inv_uom_id) std_price = pp.uom_id._compute_price( std_price, inv_uom) vals['standard_price_company_currency'] = std_price return super(AccountInvoiceLine, self).create(vals) - @api.multi def write(self, vals): if not vals: vals = {} @@ -106,7 +106,7 @@ class AccountInvoiceLine(models.Model): # uom_id is NOT a required field if 'uom_id' in vals: if vals.get('uom_id'): - inv_uom = self.env['product.uom'].browse( + inv_uom = self.env['uom.uom'].browse( vals['uom_id']) else: inv_uom = False @@ -127,11 +127,11 @@ class AccountInvoice(models.Model): margin_invoice_currency = fields.Monetary( string='Margin in Invoice Currency', - readonly=True, compute='_compute_margin', store=True, + compute='_compute_margin', store=True, readonly=True, currency_field='currency_id') margin_company_currency = fields.Monetary( string='Margin in Company Currency', - readonly=True, compute='_compute_margin', store=True, + compute='_compute_margin', store=True, readonly=True, currency_field='company_currency_id') @api.depends( @@ -139,12 +139,14 @@ class AccountInvoice(models.Model): 'invoice_line_ids.margin_invoice_currency', 'invoice_line_ids.margin_company_currency') def _compute_margin(self): - for inv in self: - margin_inv_cur = 0.0 - margin_comp_cur = 0.0 - if inv.type in ('out_invoice', 'out_refund'): - for il in inv.invoice_line_ids: - margin_inv_cur += il.margin_invoice_currency - margin_comp_cur += il.margin_company_currency - inv.margin_invoice_currency = margin_inv_cur - inv.margin_company_currency = margin_comp_cur + res = self.env['account.invoice.line'].read_group( + [('invoice_id', 'in', self.ids)], + ['invoice_id', 'margin_invoice_currency', + 'margin_company_currency'], + ['invoice_id']) + for re in res: + if re['invoice_id']: + inv = self.browse(re['invoice_id'][0]) + if inv.type in ('out_invoice', 'out_refund'): + inv.margin_invoice_currency = re['margin_invoice_currency'] + inv.margin_company_currency = re['margin_company_currency'] diff --git a/account_invoice_margin/account_invoice_report.py b/account_invoice_margin/account_invoice_report.py index 696028a..5fcf9d8 100644 --- a/account_invoice_margin/account_invoice_report.py +++ b/account_invoice_margin/account_invoice_report.py @@ -1,9 +1,8 @@ -# -*- coding: utf-8 -*- -# Copyright 2018 Akretion (http://www.akretion.com) +# Copyright 2018-2019 Akretion France (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api +from odoo import api, fields, models class AccountInvoiceReport(models.Model): @@ -19,8 +18,8 @@ class AccountInvoiceReport(models.Model): 'account_id', 'amount_total_company_signed', 'commercial_partner_id', 'company_id', 'currency_id', 'date_due', 'date_invoice', 'fiscal_position_id', - 'journal_id', 'partner_bank_id', 'partner_id', 'payment_term_id', - 'residual', 'state', 'type', 'user_id', + 'journal_id', 'number', 'partner_bank_id', 'partner_id', + 'payment_term_id', 'residual', 'state', 'type', 'user_id', ], 'account.invoice.line': [ 'account_id', 'invoice_id', 'price_subtotal', 'product_id', @@ -29,26 +28,25 @@ class AccountInvoiceReport(models.Model): ], 'product.product': ['product_tmpl_id'], 'product.template': ['categ_id'], - 'product.uom': ['category_id', 'factor', 'name', 'uom_type'], + 'uom.uom': ['category_id', 'factor', 'name', 'uom_type'], 'res.currency.rate': ['currency_id', 'name'], 'res.partner': ['country_id'], } @api.depends('currency_id', 'date', 'margin') def _compute_user_currency_margin(self): - context = dict(self._context or {}) - user_currency_id = self.env.user.company_id.currency_id - currency_rate_id = self.env['res.currency.rate'].search([ + user_currency = self.env.user.company_id.currency_id + currency_rate = self.env['res.currency.rate'].search([ ('rate', '=', 1), '|', ('company_id', '=', self.env.user.company_id.id), ('company_id', '=', False)], limit=1) - base_currency_id = currency_rate_id.currency_id - ctx = context.copy() + base_currency = currency_rate.currency_id for record in self: - ctx['date'] = record.date - record.user_currency_margin = base_currency_id.with_context( - ctx).compute(record.margin, user_currency_id) + date = record.date or fields.Date.today() + company = record.company_id + record.user_currency_margin = base_currency._convert( + record.margin, user_currency, company, date) # TODO check for refunds def _sub_select(self): diff --git a/account_invoice_margin/account_invoice_view.xml b/account_invoice_margin/account_invoice_view.xml index a8c12f4..d8f9f35 100644 --- a/account_invoice_margin/account_invoice_view.xml +++ b/account_invoice_margin/account_invoice_view.xml @@ -12,22 +12,24 @@ account.invoice.line - + + @@ -38,9 +40,9 @@ + string="Margin in Inv. Cur." groups="base.group_no_one"/> + string="Margin in Comp. Cur." groups="base.group_no_one"/> diff --git a/purchase_usability/purchase_view.xml b/purchase_usability/purchase_view.xml index 7d5b48c..9101ed7 100644 --- a/purchase_usability/purchase_view.xml +++ b/purchase_usability/purchase_view.xml @@ -30,6 +30,10 @@ + + + analytic.group_analytic_tags + diff --git a/stock_inventory_valuation_ods/__init__.py b/stock_inventory_valuation_ods/__init__.py index 9525632..3553681 100644 --- a/stock_inventory_valuation_ods/__init__.py +++ b/stock_inventory_valuation_ods/__init__.py @@ -1,3 +1 @@ -# -*- coding: utf-8 -*- - from . import stock_inventory diff --git a/stock_inventory_valuation_ods/__manifest__.py b/stock_inventory_valuation_ods/__manifest__.py index ddd51e9..7946857 100644 --- a/stock_inventory_valuation_ods/__manifest__.py +++ b/stock_inventory_valuation_ods/__manifest__.py @@ -1,12 +1,11 @@ -# -*- coding: utf-8 -*- -# © 2016-2018 Akretion (http://www.akretion.com) +# Copyright 2016-2019 Akretion France (http://www.akretion.com) # @author Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Stock Inventory Validation ODS', - 'version': '10.0.1.0.0', + 'version': '12.0.1.0.0', 'category': 'Tools', 'license': 'AGPL-3', 'summary': 'Adds a Py3o ODS report on inventories', diff --git a/stock_inventory_valuation_ods/inventory.ods b/stock_inventory_valuation_ods/inventory.ods index 49fb0d3..4524f4f 100644 Binary files a/stock_inventory_valuation_ods/inventory.ods and b/stock_inventory_valuation_ods/inventory.ods differ diff --git a/stock_inventory_valuation_ods/inventory_grouped.ods b/stock_inventory_valuation_ods/inventory_grouped.ods index bcba10f..d8331a7 100644 Binary files a/stock_inventory_valuation_ods/inventory_grouped.ods and b/stock_inventory_valuation_ods/inventory_grouped.ods differ diff --git a/stock_inventory_valuation_ods/report.xml b/stock_inventory_valuation_ods/report.xml index 4b0b74c..d2a044c 100644 --- a/stock_inventory_valuation_ods/report.xml +++ b/stock_inventory_valuation_ods/report.xml @@ -2,7 +2,7 @@ - + Inventory Valuation per Location (ODS) stock.inventory stock.inventory.ods @@ -10,16 +10,11 @@ ods stock_inventory_valuation_ods inventory.ods + report + - - Inventory Valuation per Location ODS - stock.inventory - client_print_multi - - - - + Inventory Valuation (ODS) stock.inventory stock.inventory.grouped.ods @@ -27,13 +22,9 @@ ods stock_inventory_valuation_ods inventory_grouped.ods + report + - - Inventory Valuation ODS - stock.inventory - client_print_multi - - diff --git a/stock_inventory_valuation_ods/stock_inventory.py b/stock_inventory_valuation_ods/stock_inventory.py index e9745d6..2d0283c 100644 --- a/stock_inventory_valuation_ods/stock_inventory.py +++ b/stock_inventory_valuation_ods/stock_inventory.py @@ -1,5 +1,5 @@ -# -*- coding: utf-8 -*- -# Copyright 2016-2018 Akretion (Alexis de Lattre ) +# Copyright 2016-2019 Akretion France (http://www.akretion.com/) +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models diff --git a/stock_usability/stock_view.xml b/stock_usability/stock_view.xml index d0393a4..5a70fa2 100644 --- a/stock_usability/stock_view.xml +++ b/stock_usability/stock_view.xml @@ -30,8 +30,8 @@ - - + + {}