diff --git a/account_spread_cost_revenue/README.rst b/account_spread_cost_revenue/README.rst index 6dbcfaf1..ac538f56 100644 --- a/account_spread_cost_revenue/README.rst +++ b/account_spread_cost_revenue/README.rst @@ -2,10 +2,13 @@ Cost-Revenue Spread =================== -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:560d87ede92fd18ca4a929595b6a9fd9f558f6b577e8c9bad1f8e7236ad4175d + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status @@ -14,16 +17,16 @@ Cost-Revenue Spread :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Faccount--financial--tools-lightgray.png?logo=github - :target: https://github.com/OCA/account-financial-tools/tree/14.0/account_spread_cost_revenue + :target: https://github.com/OCA/account-financial-tools/tree/16.0/account_spread_cost_revenue :alt: OCA/account-financial-tools .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/account-financial-tools-14-0/account-financial-tools-14-0-account_spread_cost_revenue + :target: https://translation.odoo-community.org/projects/account-financial-tools-16-0/account-financial-tools-16-0-account_spread_cost_revenue :alt: Translate me on Weblate -.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/92/14.0 - :alt: Try me on Runbot +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/account-financial-tools&target_branch=16.0 + :alt: Try me on Runboat -|badge1| |badge2| |badge3| |badge4| |badge5| +|badge1| |badge2| |badge3| |badge4| |badge5| Allows to spread costs or revenues over a customizable periods, to even out cost or invoice spikes. @@ -67,7 +70,7 @@ Usage Define Spread Costs/Revenues Board ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Under Invoicing -> Adviser -> Accounting Entries -> Spread Costs/Revenues, create a new spread board. +Under Invoicing -> Accounting -> Journals -> Spread Costs/Revenues, create a new spread board. Complete the definition of the spreading criteria, by setting the the fields: @@ -79,17 +82,17 @@ Complete the definition of the spreading criteria, by setting the the fields: * *Start date* * *Journal* -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/spread.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/spread.png :alt: Create a new spread board -Click on the button on the top-left to calculate the spread lines. +Click on the "Recalculate unposted lines" button on the top-left to calculate the spread lines. -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/create_spread.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/create_spread.png :alt: The spreading board is defined A cron job will automatically create the accounting moves for all the lines having date previous that the current day (today). -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/update_spread.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/update_spread.png :alt: The spreading board is updated by the cron job By default, the status of the created accounting moves is posted. @@ -104,7 +107,7 @@ Link Invoice to Spread Costs/Revenues Board Create an invoice or vendor bill in draft. On its lines, the spreading right-arrow icon are displayed in dark-grey color. -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/invoice_line_1.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/invoice_line_1.png :alt: On the invoice line the spreading icon is displayed Click on the spreading right-arrow icon. A wizard prompts to enter a *Spread Action Type*: @@ -119,11 +122,11 @@ the selected Spread Board will be automatically displayed. Go back to the draft invoice/bill. The spreading functionality is now enabled on the invoice line: the spreading right-arrow icon is now displayed in green color. -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/invoice_line_2.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/invoice_line_2.png :alt: On the invoice line the spreading icon is displayed in green color Validate the invoice/bill. Click on the spreading (green) right-arrow icon to open the spread board, then click -on the smart button *Reconciled entries*: the moves of the spread lines are reconciled with the move of the invoice line. +on the smart button *Posted entries* to see the moves of the spread lines together with the move of the invoice line. In case the Subtotal Price of the invoice line is different than the *Estimated Amount* of the spread board, the spread lines (not yet posted) will be recalculated when validating the invoice/bill. @@ -181,8 +184,8 @@ Bug Tracker Bugs are tracked on `GitHub Issues `_. In case of trouble, please check there if your issue has already been reported. -If you spotted it first, help us smashing it by providing a detailed and welcomed -`feedback `_. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -199,6 +202,7 @@ Contributors * Andrea Stirpe * Kitti U. +* Saran Lim. Other credits ~~~~~~~~~~~~~ @@ -220,14 +224,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use. -.. |maintainer-astirpe| image:: https://github.com/astirpe.png?size=40px - :target: https://github.com/astirpe - :alt: astirpe - -Current `maintainer `__: - -|maintainer-astirpe| - -This module is part of the `OCA/account-financial-tools `_ project on GitHub. +This module is part of the `OCA/account-financial-tools `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/account_spread_cost_revenue/__manifest__.py b/account_spread_cost_revenue/__manifest__.py index da224121..a4789d82 100644 --- a/account_spread_cost_revenue/__manifest__.py +++ b/account_spread_cost_revenue/__manifest__.py @@ -4,20 +4,13 @@ { "name": "Cost-Revenue Spread", "summary": "Spread costs and revenues over a custom period", - "version": "15.0.1.0.0", + "version": "16.0.1.0.0", "development_status": "Beta", "author": "Onestein,Odoo Community Association (OCA)", - "maintainers": ["astirpe"], "license": "AGPL-3", "website": "https://github.com/OCA/account-financial-tools", "category": "Accounting & Finance", "depends": ["account"], - "assets": { - "web.assets_backend": [ - "/account_spread_cost_revenue/static/src/scss/account_spread.scss", - "/account_spread_cost_revenue/static/src/js/account_spread.js", - ], - }, "data": [ "security/ir.model.access.csv", "security/account_spread_security.xml", diff --git a/account_spread_cost_revenue/models/account_move.py b/account_spread_cost_revenue/models/account_move.py index c54c340f..511c0a80 100644 --- a/account_spread_cost_revenue/models/account_move.py +++ b/account_spread_cost_revenue/models/account_move.py @@ -13,7 +13,7 @@ class AccountMove(models.Model): res = super().action_post() spreads = self.mapped("invoice_line_ids.spread_id") spreads.compute_spread_board() - # On posting of spread moves. Find their related spreads to creconcile + # On posting of spread moves. Find their related spreads to reconcile move_spreads = self.env["account.spread"].search( [("line_ids.move_id", "in", self.ids)] ) diff --git a/account_spread_cost_revenue/models/account_move_line.py b/account_spread_cost_revenue/models/account_move_line.py index 804136ae..93b1e7bd 100644 --- a/account_spread_cost_revenue/models/account_move_line.py +++ b/account_spread_cost_revenue/models/account_move_line.py @@ -129,8 +129,8 @@ class AccountMoveLine(models.Model): if aline.account_id and iline.account_id != aline.account_id: return False if ( - aline.analytic_account_id - and iline.account_analytic_id != aline.analytic_account_id + aline.analytic_distribution + and iline.analytic_distribution != aline.analytic_distribution ): return False return True diff --git a/account_spread_cost_revenue/models/account_spread.py b/account_spread_cost_revenue/models/account_spread.py index 8f8b6ec7..5ed039c1 100644 --- a/account_spread_cost_revenue/models/account_spread.py +++ b/account_spread_cost_revenue/models/account_spread.py @@ -3,7 +3,6 @@ import calendar import time -from datetime import timedelta from dateutil.relativedelta import relativedelta @@ -15,7 +14,8 @@ from odoo.tools import float_is_zero class AccountSpread(models.Model): _name = "account.spread" _description = "Account Spread" - _inherit = ["mail.thread"] + _inherit = ["mail.thread", "analytic.mixin"] + _check_company_auto = True name = fields.Char(required=True) template_id = fields.Many2one("account.spread.template", string="Spread Template") @@ -96,8 +96,15 @@ class AccountSpread(models.Model): "account.journal", compute="_compute_journal_id", readonly=False, + precompute=True, store=True, required=True, + check_company=True, + domain="[('id', 'in', suitable_journal_ids)]", + ) + suitable_journal_ids = fields.Many2many( + "account.journal", + compute="_compute_suitable_journal_ids", ) invoice_line_ids = fields.One2many( "account.move.line", "spread_id", copy=False, string="Invoice Lines" @@ -123,10 +130,6 @@ class AccountSpread(models.Model): required=True, default=lambda self: self.env.company.currency_id.id, ) - account_analytic_id = fields.Many2one( - "account.analytic.account", string="Analytic Account" - ) - analytic_tag_ids = fields.Many2many("account.analytic.tag", string="Analytic Tags") move_line_auto_post = fields.Boolean("Auto-post lines", default=True) display_create_all_moves = fields.Boolean( compute="_compute_display_create_all_moves", @@ -155,6 +158,12 @@ class AccountSpread(models.Model): res["journal_id"] = default_journal.id return res + @api.depends("company_id") + def _compute_suitable_journal_ids(self): + for spread in self: + domain = [("company_id", "=", spread.company_id.id)] + spread.suitable_journal_ids = self.env["account.journal"].search(domain) + @api.depends("invoice_type") def _compute_spread_type(self): for spread in self: @@ -248,6 +257,8 @@ class AccountSpread(models.Model): self.period_type = self.template_id.period_type if self.template_id.start_date: self.spread_date = self.template_id.start_date + if self.template_id.analytic_distribution: + self.analytic_distribution = self.template_id.analytic_distribution self.days_calc = self.template_id.days_calc @api.depends("invoice_type", "company_id") @@ -444,7 +455,7 @@ class AccountSpread(models.Model): spread_end_date = spread_start_date + relativedelta(years=number_of_periods) # calculate by days and not first day of month should compute residual day only if self.days_calc and spread_end_date.day != 1: - spread_end_date = spread_end_date - timedelta(days=1) + spread_end_date = spread_end_date - relativedelta(days=1) else: spread_end_date = self._get_last_day_of_month(spread_end_date) return spread_end_date @@ -564,6 +575,8 @@ class AccountSpread(models.Model): if mls_to_reconcile: do_reconcile = mls_to_reconcile + self.invoice_line_id do_reconcile.remove_move_reconcile() + for line in do_reconcile: + line.reconciled = False # ensure to reconcile only posted items do_reconcile = do_reconcile.filtered(lambda l: l.move_id.state == "posted") do_reconcile._check_spread_reconcile_validity() @@ -588,12 +601,13 @@ class AccountSpread(models.Model): spread.is_debit_account_deprecated = spread.debit_account_id.deprecated spread.is_credit_account_deprecated = spread.credit_account_id.deprecated - def open_reconcile_view(self): + def open_posted_view(self): action_name = "account_spread_cost_revenue.action_account_moves_all_spread" - [action] = self.env.ref(action_name).read() + action = self.env["ir.actions.act_window"]._for_xml_id(action_name) action["domain"] = [("id", "in", [])] spread_mls = self.line_ids.mapped("move_id.line_ids") - spread_mls = spread_mls.filtered(lambda m: m.reconciled) + if self.env.context.get("show_reconciled_only"): + spread_mls = spread_mls.filtered(lambda m: m.reconciled) if spread_mls: domain = [("id", "in", spread_mls.ids + [self.invoice_line_id.id])] action["domain"] = domain diff --git a/account_spread_cost_revenue/models/account_spread_line.py b/account_spread_cost_revenue/models/account_spread_line.py index 87e17795..73cb22cf 100644 --- a/account_spread_cost_revenue/models/account_spread_line.py +++ b/account_spread_cost_revenue/models/account_spread_line.py @@ -64,16 +64,10 @@ class AccountInvoiceSpreadLine(models.Model): spread_date = self.env.context.get("spread_date") or self.date spread = self.spread_id - analytic = spread.account_analytic_id - analytic_tags = [] - if self.env["account.analytic.tag"].check_access_rights( - "read", raise_exception=False - ): - analytic_tags = [(6, 0, spread.analytic_tag_ids.ids)] + analytic_distribution = spread.analytic_distribution company_currency = spread.company_id.currency_id current_currency = spread.currency_id - not_same_curr = company_currency != current_currency amount = current_currency._convert( self.amount, company_currency, spread.company_id, spread_date ) @@ -92,10 +86,9 @@ class AccountInvoiceSpreadLine(models.Model): "debit": amount if amount > 0.0 else 0.0, "credit": -amount if amount < 0.0 else 0.0, "partner_id": self.spread_id.invoice_id.partner_id.id, - "analytic_account_id": analytic.id, - "analytic_tag_ids": analytic_tags, - "currency_id": not_same_curr and current_currency.id or False, - "amount_currency": not_same_curr and -1.0 * self.amount or 0.0, + "journal_id": self.spread_id.journal_id.id, + "analytic_distribution": analytic_distribution, + "date": self.date, }, ), ( @@ -109,10 +102,9 @@ class AccountInvoiceSpreadLine(models.Model): "credit": amount if amount > 0.0 else 0.0, "debit": -amount if amount < 0.0 else 0.0, "partner_id": self.spread_id.invoice_id.partner_id.id, - "analytic_account_id": analytic.id, - "analytic_tag_ids": analytic_tags, - "currency_id": not_same_curr and current_currency.id or False, - "amount_currency": not_same_curr and self.amount or 0.0, + "journal_id": self.spread_id.journal_id.id, + "analytic_distribution": analytic_distribution, + "date": self.date, }, ), ] diff --git a/account_spread_cost_revenue/models/account_spread_template.py b/account_spread_cost_revenue/models/account_spread_template.py index 2fddd86c..afdb18e5 100644 --- a/account_spread_cost_revenue/models/account_spread_template.py +++ b/account_spread_cost_revenue/models/account_spread_template.py @@ -7,6 +7,7 @@ from odoo.exceptions import UserError class AccountSpreadTemplate(models.Model): _name = "account.spread.template" + _inherit = "analytic.mixin" _description = "Account Spread Template" name = fields.Char(required=True) @@ -147,34 +148,10 @@ class AccountSpreadTemplate(models.Model): spread_vals["invoice_type"] = invoice_type return spread_vals - @api.constrains("auto_spread_ids", "auto_spread") - def _check_auto_spread_ids_unique(self): - query = """ - select product_id, account_id, analytic_account_id - from ( - select product_id, account_id, analytic_account_id, count(*) - from account_spread_template_auto a - join account_spread_template b on a.template_id = b.id - where b.auto_spread = true and b.id in %s - group by product_id, account_id, analytic_account_id - ) x where x.count > 1 """ - self._cr.execute(query, [self._ids]) - results = [] - for res in self._cr.fetchall(): - product = self.env["product.product"].browse(res[0]) - account = self.env["account.account"].browse(res[1]) - analytic = self.env["account.analytic.account"].browse(res[2]) - results.append( - "{} / {} / {}".format(product.name, account.name, analytic.name) - ) - if results: - raise UserError( - _("Followings are duplicated combinations,\n\n%s") % "\n".join(results) - ) - class AccountSpreadTemplateAuto(models.Model): _name = "account.spread.template.auto" + _inherit = "analytic.mixin" _description = "Auto create spread, based on product/account/analytic" template_id = fields.Many2one( @@ -200,7 +177,3 @@ class AccountSpreadTemplateAuto(models.Model): comodel_name="account.account", string="Account", ) - analytic_account_id = fields.Many2one( - comodel_name="account.analytic.account", - string="Analytic", - ) diff --git a/account_spread_cost_revenue/readme/USAGE.rst b/account_spread_cost_revenue/readme/USAGE.rst index 0acc072b..3737e4b7 100644 --- a/account_spread_cost_revenue/readme/USAGE.rst +++ b/account_spread_cost_revenue/readme/USAGE.rst @@ -1,7 +1,7 @@ Define Spread Costs/Revenues Board ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -Under Invoicing -> Accounting -> Miscellaneous -> Spread Costs/Revenues, create a new spread board. +Under Invoicing -> Accounting -> Journals -> Spread Costs/Revenues, create a new spread board. Complete the definition of the spreading criteria, by setting the the fields: @@ -13,17 +13,17 @@ Complete the definition of the spreading criteria, by setting the the fields: * *Start date* * *Journal* -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/spread.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/spread.png :alt: Create a new spread board Click on the "Recalculate unposted lines" button on the top-left to calculate the spread lines. -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/create_spread.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/create_spread.png :alt: The spreading board is defined A cron job will automatically create the accounting moves for all the lines having date previous that the current day (today). -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/update_spread.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/update_spread.png :alt: The spreading board is updated by the cron job By default, the status of the created accounting moves is posted. @@ -38,7 +38,7 @@ Link Invoice to Spread Costs/Revenues Board Create an invoice or vendor bill in draft. On its lines, the spreading right-arrow icon are displayed in dark-grey color. -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/invoice_line_1.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/invoice_line_1.png :alt: On the invoice line the spreading icon is displayed Click on the spreading right-arrow icon. A wizard prompts to enter a *Spread Action Type*: @@ -53,11 +53,11 @@ the selected Spread Board will be automatically displayed. Go back to the draft invoice/bill. The spreading functionality is now enabled on the invoice line: the spreading right-arrow icon is now displayed in green color. -.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/12.0/account_spread_cost_revenue/static/description/invoice_line_2.png +.. figure:: https://raw.githubusercontent.com/OCA/account-financial-tools/16.0/account_spread_cost_revenue/static/description/invoice_line_2.png :alt: On the invoice line the spreading icon is displayed in green color Validate the invoice/bill. Click on the spreading (green) right-arrow icon to open the spread board, then click -on the smart button *Reconciled entries*: the moves of the spread lines are reconciled with the move of the invoice line. +on the smart button *Posted entries* to see the moves of the spread lines together with the move of the invoice line. In case the Subtotal Price of the invoice line is different than the *Estimated Amount* of the spread board, the spread lines (not yet posted) will be recalculated when validating the invoice/bill. diff --git a/account_spread_cost_revenue/static/description/index.html b/account_spread_cost_revenue/static/description/index.html index b391f5ae..6e3077e1 100644 --- a/account_spread_cost_revenue/static/description/index.html +++ b/account_spread_cost_revenue/static/description/index.html @@ -1,20 +1,20 @@ - + - + Cost-Revenue Spread