From 5e61990e96b2a8f9f84c2807594672809cd644e4 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Thu, 11 Aug 2022 04:28:47 -0300 Subject: [PATCH 01/19] [ADD] mis_builder_cash_flow_forecast_sale --- .../README.rst | 81 ++++++ .../__init__.py | 1 + .../__manifest__.py | 23 ++ .../data/ir_cron.xml | 18 ++ .../models/__init__.py | 4 + .../models/res_company.py | 13 + .../models/res_config_settings.py | 15 ++ .../models/sale_order.py | 252 ++++++++++++++++++ .../models/sale_order_line.py | 9 + .../readme/CONTRIBUTORS.rst | 3 + .../readme/DESCRIPTION.rst | 0 .../readme/USAGE.rst | 0 .../static/description/icon.png | Bin 0 -> 2873 bytes .../views/res_config_settings.xml | 44 +++ .../views/sale_order.xml | 22 ++ 15 files changed, 485 insertions(+) create mode 100644 mis_builder_cash_flow_forecast_sale/README.rst create mode 100644 mis_builder_cash_flow_forecast_sale/__init__.py create mode 100644 mis_builder_cash_flow_forecast_sale/__manifest__.py create mode 100644 mis_builder_cash_flow_forecast_sale/data/ir_cron.xml create mode 100644 mis_builder_cash_flow_forecast_sale/models/__init__.py create mode 100644 mis_builder_cash_flow_forecast_sale/models/res_company.py create mode 100644 mis_builder_cash_flow_forecast_sale/models/res_config_settings.py create mode 100644 mis_builder_cash_flow_forecast_sale/models/sale_order.py create mode 100644 mis_builder_cash_flow_forecast_sale/models/sale_order_line.py create mode 100644 mis_builder_cash_flow_forecast_sale/readme/CONTRIBUTORS.rst create mode 100644 mis_builder_cash_flow_forecast_sale/readme/DESCRIPTION.rst create mode 100644 mis_builder_cash_flow_forecast_sale/readme/USAGE.rst create mode 100644 mis_builder_cash_flow_forecast_sale/static/description/icon.png create mode 100644 mis_builder_cash_flow_forecast_sale/views/res_config_settings.xml create mode 100644 mis_builder_cash_flow_forecast_sale/views/sale_order.xml diff --git a/mis_builder_cash_flow_forecast_sale/README.rst b/mis_builder_cash_flow_forecast_sale/README.rst new file mode 100644 index 0000000..4edaba5 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/README.rst @@ -0,0 +1,81 @@ +=================================== +Mis Builder Cash Flow Forecast Sale +=================================== +.. |badge1| image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +|badge1| + +MIS Builder Cash Flow Forecast - Sale + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +To Configure... + +Usage +===== + +To usage... + +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 smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +~~~~~~~ + +* Escodoo + +Contributors +~~~~~~~~~~~~ + +* Marcel Savegnago + +Other credits +~~~~~~~~~~~~~ + +The development of this module has been financially supported by: + +* Escodoo - `https://www.escodoo.com.br `_ + +Maintainers +~~~~~~~~~~~ + +This module is maintained by the Escodoo. + +.. |maintainer-escodoo| image:: https://github.com/escodoo.png?size=80px + :target: https://github.com/Escodoo + :alt: escodoo + +|maintainer-escodoo| + +We at Escodoo are exclusively dedicated to deploying the Odoo Platform and are +focused on providing solutions that make our customers more competitive, lowering +costs, making technology more accessible and ensuring it is used strategically to +add even more value to the business. + +.. |maintainer-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px + :target: https://github.com/marcelsavegnago + :alt: marcelsavegnago + +Current `maintainer `__: + +|maintainer-marcelsavegnago| + +To contribute to this module, please visit https://www.escodoo.com.br. diff --git a/mis_builder_cash_flow_forecast_sale/__init__.py b/mis_builder_cash_flow_forecast_sale/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/mis_builder_cash_flow_forecast_sale/__manifest__.py b/mis_builder_cash_flow_forecast_sale/__manifest__.py new file mode 100644 index 0000000..10c2e6a --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/__manifest__.py @@ -0,0 +1,23 @@ +# Copyright 2022 - TODAY, Escodoo +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Mis Builder Cash Flow Forecast Sale", + "summary": """ + MIS Builder Cash Flow Forecast - Sale""", + "version": "12.0.1.0.0", + "license": "AGPL-3", + "author": "Escodoo", + "website": "https://github.com/Escodoo/account-addons", + "depends": [ + "mis_builder_cash_flow_forecast_integration", + "sale_management", + "queue_job", + ], + "data": [ + "views/res_config_settings.xml", + "views/sale_order.xml", + "data/ir_cron.xml", + ], + "demo": [], +} diff --git a/mis_builder_cash_flow_forecast_sale/data/ir_cron.xml b/mis_builder_cash_flow_forecast_sale/data/ir_cron.xml new file mode 100644 index 0000000..ec7ca5c --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/data/ir_cron.xml @@ -0,0 +1,18 @@ + + + + + MIS Builder Cash Flow - Generate Forecast - Sale Order + + code + model.cron_mis_cash_flow_generate_forecast_lines() + + 1 + days + -1 + + + + diff --git a/mis_builder_cash_flow_forecast_sale/models/__init__.py b/mis_builder_cash_flow_forecast_sale/models/__init__.py new file mode 100644 index 0000000..25d3b6b --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/models/__init__.py @@ -0,0 +1,4 @@ +from . import res_company +from . import res_config_settings +from . import sale_order_line +from . import sale_order diff --git a/mis_builder_cash_flow_forecast_sale/models/res_company.py b/mis_builder_cash_flow_forecast_sale/models/res_company.py new file mode 100644 index 0000000..a0682bf --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/models/res_company.py @@ -0,0 +1,13 @@ +# Copyright 2022 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResCompany(models.Model): + + _inherit = "res.company" + + enable_sale_mis_cash_flow_forecast = fields.Boolean( + string="Enable MIS Builder Cash Flow Forecast - Sale", default=True + ) diff --git a/mis_builder_cash_flow_forecast_sale/models/res_config_settings.py b/mis_builder_cash_flow_forecast_sale/models/res_config_settings.py new file mode 100644 index 0000000..977f53c --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/models/res_config_settings.py @@ -0,0 +1,15 @@ +# Copyright 2022 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + + _inherit = "res.config.settings" + + enable_sale_mis_cash_flow_forecast = fields.Boolean( + string="Enable MIS Builder Cash Flow Forecast - Sale", + readonly=False, + related="company_id.enable_sale_mis_cash_flow_forecast", + ) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py new file mode 100644 index 0000000..c8560e4 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -0,0 +1,252 @@ +# Copyright 2022 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + + +from odoo import api, fields, models + + +class SaleOrder(models.Model): + + _inherit = "sale.order" + + forecast_uninvoiced_amount = fields.Monetary( + string="Forecast Uninvoiced Amount", + readonly=True, + compute="_compute_forecast_uninvoiced_amount", + tracking=True, + ) + + mis_cash_flow_forecast_line_ids = fields.One2many( + comodel_name="mis.cash_flow.forecast_line", + compute="_compute_mis_cash_flow_forecast_line_ids", + string="Forecast Line", + required=False, + ) + + mis_cash_flow_forecast_line_count = fields.Integer( + compute="_compute_mis_cash_flow_forecast_line_ids", + string="Forecast Line Count", + ) + + @api.depends( + "order_line.product_uom_qty", + "order_line.qty_invoiced", + "order_line.product_id", + "order_line.product_uom", + "order_line.price_unit", + ) + def _compute_forecast_uninvoiced_amount(self): + for order in self: + forecast_uninvoiced_amount = 0 + for line in order.order_line: + qty = line.product_uom_qty - line.qty_invoiced + # we use this way for being compatible with sale_discount + price_unit = ( + line.price_subtotal / line.product_uom_qty + if line.product_uom_qty + else line.price_unit + ) + forecast_uninvoiced_amount += qty * price_unit + if forecast_uninvoiced_amount < 0 or order.state not in [ + "sale", + "done", + ]: + forecast_uninvoiced_amount = 0 + order.update( + { + "forecast_uninvoiced_amount": order.currency_id.round( + forecast_uninvoiced_amount + ) + } + ) + + def _compute_mis_cash_flow_forecast_line_ids(self): + ForecastLine = self.env["mis.cash_flow.forecast_line"] + forecast_lines = ForecastLine.search( + [ + ("res_model", "=", self._name), + ("res_id", "in", self.ids), + ] + ) + + result = dict.fromkeys(self.ids, ForecastLine) + for forecast in forecast_lines: + result[forecast.res_id] |= forecast + + for rec in self: + rec.mis_cash_flow_forecast_line_ids = result[rec.id] + rec.mis_cash_flow_forecast_line_count = len( + rec.mis_cash_flow_forecast_line_ids + ) + + def _compute_payment_terms(self, date, total_balance, total_amount_currency): + """Compute the payment terms. + :param self: The current account.move record. + :param date: The date computed by + '_get_payment_terms_computation_date'. + :param total_balance: The invoice's total in company's currency. + :param total_amount_currency: The invoice's total in invoice's currency. + :return: A list . + """ + if self.payment_term_id: + to_compute = self.payment_term_id.compute( + total_balance, date_ref=date, currency=self.company_id.currency_id + ) + if self.currency_id == self.company_id.currency_id: + # Single-currency. + return [(b[0], b[1], b[1]) for b in to_compute] + else: + # Multi-currencies. + to_compute_currency = self.payment_term_id.compute( + total_amount_currency, date_ref=date, currency=self.currency_id + ) + return [ + (b[0], b[1], ac[1]) + for b, ac in zip(to_compute, to_compute_currency) + ] + else: + return [(fields.Date.to_string(date), total_balance, total_amount_currency)] + + @api.model + def _get_mis_cash_flow_forecast_update_trigger_fields(self): + return [ + "partner_id", + "pricelist_id", + "fiscal_position_id", + "currency_id", + "order_line", + "payment_term_id", + "currency_rate", + "invoice_status", + "invoice_count", + "invoice_ids", + "state", + "forecast_uninvoiced_amount", + ] + + @api.model + def create(self, values): + sale_orders = super(SaleOrder, self).create(values) + for sale_order in sale_orders: + if sale_order.company_id.enable_sale_mis_cash_flow_forecast: + sale_order.with_delay()._generate_mis_cash_flow_forecast_lines() + return sale_orders + + def write(self, values): + res = super(SaleOrder, self).write(values) + if any( + [ + field in values + for field in self._get_mis_cash_flow_forecast_update_trigger_fields() + ] + ): + for rec in self: + if rec.company_id.enable_sale_mis_cash_flow_forecast: + # rec.with_delay()._generate_mis_cash_flow_forecast_lines() + rec._generate_mis_cash_flow_forecast_lines() + return res + + def unlink(self): + for rec in self: + for line in rec.order_line: + if line.mis_cash_flow_forecast_line_ids: + line.mis_cash_flow_forecast_line_ids.unlink() + return super().unlink() + + def _prepare_mis_cash_flow_forecast_line( + self, payment_term_item, payment_term_count, date, amount + ): + self.ensure_one() + parent_res_id = self + parent_res_model_id = self.env["ir.model"]._get(parent_res_id._name) + + account_id = ( + self.partner_id.property_account_receivable_id.id + or self.env["ir.property"] + ._get("property_account_receivable_id", "res.partner") + .id + ) + + return { + "name": "%s - %s/%s" + % ( + self.display_name, + payment_term_item, + payment_term_count, + ), + "date": date, + "account_id": account_id, + "partner_id": self.partner_id.id, + "balance": amount, + "company_id": self.company_id.id, + "res_model_id": self.env["ir.model"]._get(self._name).id, + "res_id": self.id, + "parent_res_model_id": parent_res_model_id.id, + "parent_res_id": parent_res_id.id, + } + + def _generate_mis_cash_flow_forecast_lines(self): + values = [] + for rec in self: + rec.mis_cash_flow_forecast_line_ids.unlink() + if rec.forecast_uninvoiced_amount and rec.state in ["sale", "done"]: + sign = 1 + subtotal = rec.forecast_uninvoiced_amount + price_subtotal_signed = subtotal * sign + price_subtotal_company_signed = price_subtotal_signed + if ( + rec.currency_id + and rec.company_id + and rec.currency_id != rec.company_id.currency_id + ): + cur = rec.currency_id + price_subtotal = cur.round(subtotal) + price_subtotal_signed = cur.round(price_subtotal_signed) + rate_date = rec.expected_date or fields.Date.today() + price_subtotal_company = cur._convert( + price_subtotal, + rec.company_id.currency_id, + rec.company_id, + rate_date, + ) + price_subtotal_company_signed = price_subtotal_company * sign + + payment_terms = rec._compute_payment_terms( + rec.expected_date, + price_subtotal_company_signed, + price_subtotal_signed, + ) + + payment_term_count = len(payment_terms) + payment_term_line = 0 + + for payment_term in payment_terms: + payment_term_line += 1 + new_vals = rec._prepare_mis_cash_flow_forecast_line( + payment_term_line, + payment_term_count, + payment_term[0], + payment_term[1], + ) + values.append(new_vals) + + return self.env["mis.cash_flow.forecast_line"].create(values) + + @api.model + def cron_mis_cash_flow_generate_forecast_lines(self): + offset = 0 + while True: + sale_orders = self.search( + [("forecast_uninvoiced_amount", ">", 0)], limit=100, offset=offset + ) + sale_orders.with_delay()._generate_mis_cash_flow_forecast_lines() + if len(sale_orders) < 100: + break + offset += 100 + + def _create_invoices(self, grouped=False, final=False, date=None): + moves = super()._create_invoices(grouped=grouped, final=final, date=date) + for rec in self: + rec.with_delay()._generate_mis_cash_flow_forecast_lines() + return moves diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order_line.py b/mis_builder_cash_flow_forecast_sale/models/sale_order_line.py new file mode 100644 index 0000000..a2cd73d --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order_line.py @@ -0,0 +1,9 @@ +# Copyright 2022 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class SaleOrderLine(models.Model): + + _inherit = "sale.order.line" diff --git a/mis_builder_cash_flow_forecast_sale/readme/CONTRIBUTORS.rst b/mis_builder_cash_flow_forecast_sale/readme/CONTRIBUTORS.rst new file mode 100644 index 0000000..ae453a6 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/readme/CONTRIBUTORS.rst @@ -0,0 +1,3 @@ +* `Escodoo `_: + + * Marcel Savegnago diff --git a/mis_builder_cash_flow_forecast_sale/readme/DESCRIPTION.rst b/mis_builder_cash_flow_forecast_sale/readme/DESCRIPTION.rst new file mode 100644 index 0000000..e69de29 diff --git a/mis_builder_cash_flow_forecast_sale/readme/USAGE.rst b/mis_builder_cash_flow_forecast_sale/readme/USAGE.rst new file mode 100644 index 0000000..e69de29 diff --git a/mis_builder_cash_flow_forecast_sale/static/description/icon.png b/mis_builder_cash_flow_forecast_sale/static/description/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..12ab0051e3b9ac413f0f0016b7cff54f02fc763e GIT binary patch literal 2873 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 XXqTGI$C0NT00000NkvXXu0mjf?G|(} literal 0 HcmV?d00001 diff --git a/mis_builder_cash_flow_forecast_sale/views/res_config_settings.xml b/mis_builder_cash_flow_forecast_sale/views/res_config_settings.xml new file mode 100644 index 0000000..c1b5849 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/views/res_config_settings.xml @@ -0,0 +1,44 @@ + + + + + + res.config.settings in (mis_builder_cash_flow_forecast_sale) + res.config.settings + + + +
+
+
+ +
+
+
+
+
+
+
+
+ +
diff --git a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml new file mode 100644 index 0000000..8b96d69 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml @@ -0,0 +1,22 @@ + + + + + sale.order.tree in (mis_builder_cash_flow_forecast_sale) + sale.order + + + + + + + + From 5269b7aa175960c94677270bf602fc118b87249d Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Thu, 11 Aug 2022 14:40:44 -0300 Subject: [PATCH 02/19] [FIX] mis_builder_cash_flow_forecast_sale: fix job call --- mis_builder_cash_flow_forecast_sale/models/sale_order.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index c8560e4..e9ff7f6 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -143,8 +143,7 @@ def write(self, values): ): for rec in self: if rec.company_id.enable_sale_mis_cash_flow_forecast: - # rec.with_delay()._generate_mis_cash_flow_forecast_lines() - rec._generate_mis_cash_flow_forecast_lines() + rec.with_delay()._generate_mis_cash_flow_forecast_lines() return res def unlink(self): From f97b24f3011e47efd5514a6fb0027e295481b231 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Thu, 11 Aug 2022 17:55:42 -0300 Subject: [PATCH 03/19] [IMP] mis_builder_cash_flow_forecast_sale: add _compute_amount_uninvoiced_company_currency and refactor _generate_mis_cash_flow_forecast_lines --- .../models/sale_order.py | 42 +++++++++++-------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index e9ff7f6..96ffc9d 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -108,6 +108,23 @@ def _compute_payment_terms(self, date, total_balance, total_amount_currency): else: return [(fields.Date.to_string(date), total_balance, total_amount_currency)] + def _compute_amount_uninvoiced_company_currency(self, amount_uninvoiced): + if ( + self.currency_id + and self.company_id + and self.currency_id != self.company_id.currency_id + ): + cur = self.currency_id + price_subtotal = cur.round(amount_uninvoiced) + rate_date = self.expected_date or fields.Date.today() + amount_uninvoiced = cur._convert( + price_subtotal, + self.company_id.currency_id, + self.company_id, + rate_date, + ) + return amount_uninvoiced + @api.model def _get_mis_cash_flow_forecast_update_trigger_fields(self): return [ @@ -190,31 +207,22 @@ def _generate_mis_cash_flow_forecast_lines(self): for rec in self: rec.mis_cash_flow_forecast_line_ids.unlink() if rec.forecast_uninvoiced_amount and rec.state in ["sale", "done"]: - sign = 1 - subtotal = rec.forecast_uninvoiced_amount - price_subtotal_signed = subtotal * sign - price_subtotal_company_signed = price_subtotal_signed + amount_uninvoiced = rec.forecast_uninvoiced_amount + if ( rec.currency_id and rec.company_id and rec.currency_id != rec.company_id.currency_id ): cur = rec.currency_id - price_subtotal = cur.round(subtotal) - price_subtotal_signed = cur.round(price_subtotal_signed) - rate_date = rec.expected_date or fields.Date.today() - price_subtotal_company = cur._convert( - price_subtotal, - rec.company_id.currency_id, - rec.company_id, - rate_date, - ) - price_subtotal_company_signed = price_subtotal_company * sign - + amount_uninvoiced = cur.round(amount_uninvoiced) + amount_uninvoiced_company = ( + rec._compute_amount_uninvoiced_company_currency(amount_uninvoiced) + ) payment_terms = rec._compute_payment_terms( rec.expected_date, - price_subtotal_company_signed, - price_subtotal_signed, + amount_uninvoiced_company, + amount_uninvoiced, ) payment_term_count = len(payment_terms) From d0213fb2eef91daa39d83cd36115c4a2d8e9735a Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Thu, 11 Aug 2022 20:14:36 -0300 Subject: [PATCH 04/19] [MIG] mis_builder_cash_flow_forecast_sale: 12.0 from 14.0 --- .../models/sale_order.py | 17 +++++++---------- .../views/sale_order.xml | 3 +-- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index 96ffc9d..f288c5e 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -177,12 +177,9 @@ def _prepare_mis_cash_flow_forecast_line( parent_res_id = self parent_res_model_id = self.env["ir.model"]._get(parent_res_id._name) - account_id = ( - self.partner_id.property_account_receivable_id.id - or self.env["ir.property"] - ._get("property_account_receivable_id", "res.partner") - .id - ) + account_id = self.partner_id.property_account_receivable_id or self.env[ + "ir.property" + ].get("property_account_receivable_id", "res.partner") return { "name": "%s - %s/%s" @@ -192,7 +189,7 @@ def _prepare_mis_cash_flow_forecast_line( payment_term_count, ), "date": date, - "account_id": account_id, + "account_id": account_id.id, "partner_id": self.partner_id.id, "balance": amount, "company_id": self.company_id.id, @@ -252,8 +249,8 @@ def cron_mis_cash_flow_generate_forecast_lines(self): break offset += 100 - def _create_invoices(self, grouped=False, final=False, date=None): - moves = super()._create_invoices(grouped=grouped, final=final, date=date) + def action_invoice_create(self, grouped=False, final=False): + res = super().action_invoice_create(grouped=grouped, final=final) for rec in self: rec.with_delay()._generate_mis_cash_flow_forecast_lines() - return moves + return res diff --git a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml index 8b96d69..1d04690 100644 --- a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml +++ b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml @@ -9,12 +9,11 @@ sale.order - + From 19860a76ac6a5ccd56924728c186a9a0de816b1a Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Mon, 15 Aug 2022 20:18:03 -0300 Subject: [PATCH 05/19] [FIX] mis_builder_cash_flow_forecast_sale: fix payment_term_id compute --- mis_builder_cash_flow_forecast_sale/models/sale_order.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index f288c5e..ebf3441 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -90,16 +90,14 @@ def _compute_payment_terms(self, date, total_balance, total_amount_currency): to_pay_invoice_currency, due_date>. """ if self.payment_term_id: - to_compute = self.payment_term_id.compute( - total_balance, date_ref=date, currency=self.company_id.currency_id - ) + to_compute = self.payment_term_id.compute(total_balance, date_ref=date) if self.currency_id == self.company_id.currency_id: # Single-currency. return [(b[0], b[1], b[1]) for b in to_compute] else: # Multi-currencies. to_compute_currency = self.payment_term_id.compute( - total_amount_currency, date_ref=date, currency=self.currency_id + total_amount_currency, date_ref=date ) return [ (b[0], b[1], ac[1]) From f59b1262237e78867bf5e14be7dbd452881ad128 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Mon, 15 Aug 2022 21:12:07 -0300 Subject: [PATCH 06/19] [IMP] mis_builder_cash_flow_forecast_sale: add hooks.py --- mis_builder_cash_flow_forecast_sale/__init__.py | 1 + mis_builder_cash_flow_forecast_sale/hooks.py | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 mis_builder_cash_flow_forecast_sale/hooks.py diff --git a/mis_builder_cash_flow_forecast_sale/__init__.py b/mis_builder_cash_flow_forecast_sale/__init__.py index 0650744..1d353d7 100644 --- a/mis_builder_cash_flow_forecast_sale/__init__.py +++ b/mis_builder_cash_flow_forecast_sale/__init__.py @@ -1 +1,2 @@ +from .hooks import post_init_hook from . import models diff --git a/mis_builder_cash_flow_forecast_sale/hooks.py b/mis_builder_cash_flow_forecast_sale/hooks.py new file mode 100644 index 0000000..5752de8 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/hooks.py @@ -0,0 +1,12 @@ +# Copyright (C) 2022 - TODAY, Marcel Savegnago +# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html + +from odoo import SUPERUSER_ID, api + + +def post_init_hook(cr, registry): + + env = api.Environment(cr, SUPERUSER_ID, {}) + orders = env["sale.order"].search([("state", "in", ["sale", "done"])]) + if orders: + orders.sudo()._compute_forecast_uninvoiced_amount() From f9cd1d12d77be88de384125fa84ad3eef0c0a32a Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Tue, 16 Aug 2022 11:01:34 -0300 Subject: [PATCH 07/19] [FIX] mis_builder_cash_flow_forecast_sale: fix _compute_payment_terms --- mis_builder_cash_flow_forecast_sale/models/sale_order.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index ebf3441..89ba5a0 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -93,7 +93,7 @@ def _compute_payment_terms(self, date, total_balance, total_amount_currency): to_compute = self.payment_term_id.compute(total_balance, date_ref=date) if self.currency_id == self.company_id.currency_id: # Single-currency. - return [(b[0], b[1], b[1]) for b in to_compute] + return [(b[0], b[1], b[1]) for b in to_compute[0]] else: # Multi-currencies. to_compute_currency = self.payment_term_id.compute( @@ -101,7 +101,7 @@ def _compute_payment_terms(self, date, total_balance, total_amount_currency): ) return [ (b[0], b[1], ac[1]) - for b, ac in zip(to_compute, to_compute_currency) + for b, ac in zip(to_compute[0], to_compute_currency[0]) ] else: return [(fields.Date.to_string(date), total_balance, total_amount_currency)] From b4259f3bae58c5a42c8d3bc5a17878f59fa8456b Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Tue, 16 Aug 2022 11:41:11 -0300 Subject: [PATCH 08/19] [FIX] mis_builder_cash_flow_forecast_sale: fix multicompany --- mis_builder_cash_flow_forecast_sale/models/sale_order.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index 89ba5a0..d82aba3 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -175,7 +175,9 @@ def _prepare_mis_cash_flow_forecast_line( parent_res_id = self parent_res_model_id = self.env["ir.model"]._get(parent_res_id._name) - account_id = self.partner_id.property_account_receivable_id or self.env[ + partner = self.partner_id.with_context(force_company=self.company_id.id) + + account_id = partner.property_account_receivable_id or self.env[ "ir.property" ].get("property_account_receivable_id", "res.partner") From 0583dc1153780b6a0289f27f816b7f5239d1c3fb Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Thu, 18 Aug 2022 14:36:06 -0300 Subject: [PATCH 09/19] [RFC] mis_builder_cash_flow_forecast_sale: refactor --- .../models/__init__.py | 1 + .../models/account_invoice.py | 17 ++++ .../models/sale_order.py | 90 +++++++++---------- .../views/sale_order.xml | 14 +++ 4 files changed, 74 insertions(+), 48 deletions(-) create mode 100644 mis_builder_cash_flow_forecast_sale/models/account_invoice.py diff --git a/mis_builder_cash_flow_forecast_sale/models/__init__.py b/mis_builder_cash_flow_forecast_sale/models/__init__.py index 25d3b6b..c36dfda 100644 --- a/mis_builder_cash_flow_forecast_sale/models/__init__.py +++ b/mis_builder_cash_flow_forecast_sale/models/__init__.py @@ -2,3 +2,4 @@ from . import res_config_settings from . import sale_order_line from . import sale_order +from . import account_invoice diff --git a/mis_builder_cash_flow_forecast_sale/models/account_invoice.py b/mis_builder_cash_flow_forecast_sale/models/account_invoice.py new file mode 100644 index 0000000..b288f30 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/models/account_invoice.py @@ -0,0 +1,17 @@ +# Copyright 2022 - TODAY, Marcel Savegnago +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class AccountInvoice(models.Model): + + _inherit = "account.invoice" + + def invoice_validate(self): + res = super().invoice_validate() + for invoice in self: + order = invoice.invoice_line_ids.mapped("sale_line_ids.order_id") + if order and order.company_id.enable_sale_mis_cash_flow_forecast: + order.with_delay()._generate_mis_cash_flow_forecast_lines() + return res diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index d82aba3..bc71b29 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -13,7 +13,7 @@ class SaleOrder(models.Model): string="Forecast Uninvoiced Amount", readonly=True, compute="_compute_forecast_uninvoiced_amount", - tracking=True, + store=True, ) mis_cash_flow_forecast_line_ids = fields.One2many( @@ -29,36 +29,34 @@ class SaleOrder(models.Model): ) @api.depends( - "order_line.product_uom_qty", + "partner_id", + "amount_total", + "pricelist_id", + "currency_id", + "order_line.invoice_lines", "order_line.qty_invoiced", - "order_line.product_id", - "order_line.product_uom", - "order_line.price_unit", ) def _compute_forecast_uninvoiced_amount(self): for order in self: - forecast_uninvoiced_amount = 0 - for line in order.order_line: - qty = line.product_uom_qty - line.qty_invoiced - # we use this way for being compatible with sale_discount - price_unit = ( - line.price_subtotal / line.product_uom_qty - if line.product_uom_qty - else line.price_unit + amount_invoiced = sum( + x.amount_total + for x in order.invoice_ids.filtered( + lambda x: x.state in ["open", "in_payment", "paid"] ) - forecast_uninvoiced_amount += qty * price_unit - if forecast_uninvoiced_amount < 0 or order.state not in [ - "sale", - "done", - ]: - forecast_uninvoiced_amount = 0 - order.update( - { - "forecast_uninvoiced_amount": order.currency_id.round( - forecast_uninvoiced_amount - ) - } ) + forecast_uninvoiced_amount = order.amount_total - amount_invoiced + if forecast_uninvoiced_amount < 0 or order.state in [ + "cancel", + ]: + forecast_uninvoiced_amount = 0 + if order.forecast_uninvoiced_amount != forecast_uninvoiced_amount: + order.update( + { + "forecast_uninvoiced_amount": order.currency_id.round( + forecast_uninvoiced_amount + ) + } + ) def _compute_mis_cash_flow_forecast_line_ids(self): ForecastLine = self.env["mis.cash_flow.forecast_line"] @@ -134,20 +132,11 @@ def _get_mis_cash_flow_forecast_update_trigger_fields(self): "payment_term_id", "currency_rate", "invoice_status", - "invoice_count", - "invoice_ids", "state", - "forecast_uninvoiced_amount", + "invoice_ids", + "invoice_count", ] - @api.model - def create(self, values): - sale_orders = super(SaleOrder, self).create(values) - for sale_order in sale_orders: - if sale_order.company_id.enable_sale_mis_cash_flow_forecast: - sale_order.with_delay()._generate_mis_cash_flow_forecast_lines() - return sale_orders - def write(self, values): res = super(SaleOrder, self).write(values) if any( @@ -157,7 +146,11 @@ def write(self, values): ] ): for rec in self: - if rec.company_id.enable_sale_mis_cash_flow_forecast: + if ( + values.get("state") in ["sale", "done", "cancel"] + or rec.state in ["sale", "done"] + and rec.company_id.enable_sale_mis_cash_flow_forecast + ): rec.with_delay()._generate_mis_cash_flow_forecast_lines() return res @@ -204,7 +197,8 @@ def _generate_mis_cash_flow_forecast_lines(self): for rec in self: rec.mis_cash_flow_forecast_line_ids.unlink() if rec.forecast_uninvoiced_amount and rec.state in ["sale", "done"]: - amount_uninvoiced = rec.forecast_uninvoiced_amount + sign = 1 + amount_uninvoiced = rec.forecast_uninvoiced_amount * sign if ( rec.currency_id @@ -213,6 +207,7 @@ def _generate_mis_cash_flow_forecast_lines(self): ): cur = rec.currency_id amount_uninvoiced = cur.round(amount_uninvoiced) + amount_uninvoiced_company = ( rec._compute_amount_uninvoiced_company_currency(amount_uninvoiced) ) @@ -241,16 +236,15 @@ def _generate_mis_cash_flow_forecast_lines(self): def cron_mis_cash_flow_generate_forecast_lines(self): offset = 0 while True: - sale_orders = self.search( - [("forecast_uninvoiced_amount", ">", 0)], limit=100, offset=offset + orders = self.search( + [ + ("forecast_uninvoiced_amount", ">", 0), + ("state", "in", ["sale", "done"]), + ], + limit=100, + offset=offset, ) - sale_orders.with_delay()._generate_mis_cash_flow_forecast_lines() - if len(sale_orders) < 100: + orders.with_delay()._generate_mis_cash_flow_forecast_lines() + if len(orders) < 100: break offset += 100 - - def action_invoice_create(self, grouped=False, final=False): - res = super().action_invoice_create(grouped=grouped, final=final) - for rec in self: - rec.with_delay()._generate_mis_cash_flow_forecast_lines() - return res diff --git a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml index 1d04690..5e917d3 100644 --- a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml +++ b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml @@ -2,6 +2,20 @@ + + + sale.order.form in (mis_builder_cash_flow_forecast_sale) + sale.order + + + + + + + + Date: Thu, 18 Aug 2022 15:01:16 -0300 Subject: [PATCH 10/19] [FIX] mis_builder_cash_flow_forecast_sale: fix sale order tree view --- mis_builder_cash_flow_forecast_sale/views/sale_order.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml index 5e917d3..a494269 100644 --- a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml +++ b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml @@ -23,7 +23,7 @@ sale.order - + Date: Fri, 19 Aug 2022 11:00:18 -0300 Subject: [PATCH 11/19] [IMP] mis_builder_cash_flow_forecast_sale: imp forecast button on order view --- .../models/sale_order.py | 22 ++++++++++++++++++- .../views/sale_order.xml | 18 ++++++++++++++- 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index bc71b29..fc9e1d5 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -2,7 +2,7 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import api, fields, models +from odoo import _, api, fields, models class SaleOrder(models.Model): @@ -248,3 +248,23 @@ def cron_mis_cash_flow_generate_forecast_lines(self): if len(orders) < 100: break offset += 100 + + @api.multi + def action_show_mis_forecast(self): + self.ensure_one() + context = { + "search_default_groupby_date": True, + } + context.update(self.env.context) + + return { + "type": "ir.actions.act_window", + "name": _("Cash Flow Forecast - Sale"), + "res_model": "mis.cash_flow.forecast_line", + "domain": [ + ("parent_res_model", "=", self._name), + ("parent_res_id", "=", self.id), + ], + "view_mode": "pivot,tree", + "context": context, + } diff --git a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml index a494269..27b1dfa 100644 --- a/mis_builder_cash_flow_forecast_sale/views/sale_order.xml +++ b/mis_builder_cash_flow_forecast_sale/views/sale_order.xml @@ -12,7 +12,23 @@ + + + + @@ -23,7 +39,7 @@ sale.order - + Date: Fri, 19 Aug 2022 15:17:08 -0300 Subject: [PATCH 12/19] [FIX] mis_builder_cash_flow_forecast_sale: fix action_show_mis_forecast --- mis_builder_cash_flow_forecast_sale/models/sale_order.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index fc9e1d5..aca63c0 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -252,10 +252,8 @@ def cron_mis_cash_flow_generate_forecast_lines(self): @api.multi def action_show_mis_forecast(self): self.ensure_one() - context = { - "search_default_groupby_date": True, - } - context.update(self.env.context) + context = dict(self.env.context) + context.pop("group_by", None) return { "type": "ir.actions.act_window", From 078ff8dc7f4a621bacee2232c729ea203b54b828 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Thu, 17 Nov 2022 14:24:21 -0300 Subject: [PATCH 13/19] [FIX] mis_builder_cash_flow_forecast_sale: unlink method --- mis_builder_cash_flow_forecast_sale/models/sale_order.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index aca63c0..362601c 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -156,9 +156,8 @@ def write(self, values): def unlink(self): for rec in self: - for line in rec.order_line: - if line.mis_cash_flow_forecast_line_ids: - line.mis_cash_flow_forecast_line_ids.unlink() + if rec.mis_cash_flow_forecast_line_ids: + rec.mis_cash_flow_forecast_line_ids.unlink() return super().unlink() def _prepare_mis_cash_flow_forecast_line( From 09f256191c73c83077344f8f17032cf9274def86 Mon Sep 17 00:00:00 2001 From: Marcel Savegnago Date: Thu, 1 Dec 2022 19:15:23 -0300 Subject: [PATCH 14/19] [MIG] mis_builder_cash_flow_forecast_sale: Migration to 14.0 --- .../README.rst | 74 ++- .../__manifest__.py | 2 +- .../models/account_invoice.py | 40 +- .../models/sale_order.py | 31 +- .../static/description/index.html | 421 ++++++++++++++++++ 5 files changed, 507 insertions(+), 61 deletions(-) create mode 100644 mis_builder_cash_flow_forecast_sale/static/description/index.html diff --git a/mis_builder_cash_flow_forecast_sale/README.rst b/mis_builder_cash_flow_forecast_sale/README.rst index 4edaba5..23618c8 100644 --- a/mis_builder_cash_flow_forecast_sale/README.rst +++ b/mis_builder_cash_flow_forecast_sale/README.rst @@ -1,36 +1,40 @@ =================================== Mis Builder Cash Flow Forecast Sale =================================== -.. |badge1| image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + +.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :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--addons-lightgray.png?logo=github + :target: https://github.com/OCA/account-addons/tree/14.0/mis_builder_cash_flow_forecast_sale + :alt: OCA/account-addons +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/account-addons-14-0/account-addons-14-0-mis_builder_cash_flow_forecast_sale + :alt: Translate me on Weblate -|badge1| +|badge1| |badge2| |badge3| |badge4| -MIS Builder Cash Flow Forecast - Sale **Table of contents** .. contents:: :local: -Configuration -============= - -To Configure... - -Usage -===== - -To usage... - 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 smash it by providing detailed and welcomed feedback. +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 `_. Do not contact contributors directly about support or help with technical issues. @@ -45,37 +49,23 @@ Authors Contributors ~~~~~~~~~~~~ -* Marcel Savegnago +* `Escodoo `_: -Other credits -~~~~~~~~~~~~~ - -The development of this module has been financially supported by: - -* Escodoo - `https://www.escodoo.com.br `_ + * Marcel Savegnago Maintainers ~~~~~~~~~~~ -This module is maintained by the Escodoo. - -.. |maintainer-escodoo| image:: https://github.com/escodoo.png?size=80px - :target: https://github.com/Escodoo - :alt: escodoo - -|maintainer-escodoo| - -We at Escodoo are exclusively dedicated to deploying the Odoo Platform and are -focused on providing solutions that make our customers more competitive, lowering -costs, making technology more accessible and ensuring it is used strategically to -add even more value to the business. +This module is maintained by the OCA. -.. |maintainer-marcelsavegnago| image:: https://github.com/marcelsavegnago.png?size=40px - :target: https://github.com/marcelsavegnago - :alt: marcelsavegnago +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org -Current `maintainer `__: +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-marcelsavegnago| +This module is part of the `OCA/account-addons `_ project on GitHub. -To contribute to this module, please visit https://www.escodoo.com.br. +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/mis_builder_cash_flow_forecast_sale/__manifest__.py b/mis_builder_cash_flow_forecast_sale/__manifest__.py index 10c2e6a..ef247d1 100644 --- a/mis_builder_cash_flow_forecast_sale/__manifest__.py +++ b/mis_builder_cash_flow_forecast_sale/__manifest__.py @@ -5,7 +5,7 @@ "name": "Mis Builder Cash Flow Forecast Sale", "summary": """ MIS Builder Cash Flow Forecast - Sale""", - "version": "12.0.1.0.0", + "version": "14.0.1.0.0", "license": "AGPL-3", "author": "Escodoo", "website": "https://github.com/Escodoo/account-addons", diff --git a/mis_builder_cash_flow_forecast_sale/models/account_invoice.py b/mis_builder_cash_flow_forecast_sale/models/account_invoice.py index b288f30..6c377a5 100644 --- a/mis_builder_cash_flow_forecast_sale/models/account_invoice.py +++ b/mis_builder_cash_flow_forecast_sale/models/account_invoice.py @@ -1,17 +1,43 @@ # Copyright 2022 - TODAY, Marcel Savegnago # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -from odoo import models +from odoo import api, models -class AccountInvoice(models.Model): +class AccountMove(models.Model): - _inherit = "account.invoice" + _inherit = "account.move" - def invoice_validate(self): - res = super().invoice_validate() - for invoice in self: - order = invoice.invoice_line_ids.mapped("sale_line_ids.order_id") + def action_post(self): + res = super().action_post() + for move in self: + order = move.invoice_line_ids.mapped("sale_line_ids.order_id") if order and order.company_id.enable_sale_mis_cash_flow_forecast: order.with_delay()._generate_mis_cash_flow_forecast_lines() return res + + def button_cancel(self): + super().button_cancel() + for move in self: + order = move.invoice_line_ids.mapped("sale_line_ids.order_id") + if order and order.company_id.enable_sale_mis_cash_flow_forecast: + order._compute_forecast_uninvoiced_amount() + order.with_delay()._generate_mis_cash_flow_forecast_lines() + + def button_draft(self): + super().button_draft() + for move in self: + order = move.invoice_line_ids.mapped("sale_line_ids.order_id") + if order and order.company_id.enable_sale_mis_cash_flow_forecast: + order._compute_forecast_uninvoiced_amount() + order.with_delay()._generate_mis_cash_flow_forecast_lines() + + @api.model + def create(self, vals_list): + moves = super().create(vals_list) + for move in moves: + order = move.invoice_line_ids.mapped("sale_line_ids.order_id") + if order and order.company_id.enable_sale_mis_cash_flow_forecast: + order._compute_forecast_uninvoiced_amount() + order.with_delay()._generate_mis_cash_flow_forecast_lines() + return moves diff --git a/mis_builder_cash_flow_forecast_sale/models/sale_order.py b/mis_builder_cash_flow_forecast_sale/models/sale_order.py index 362601c..e175486 100644 --- a/mis_builder_cash_flow_forecast_sale/models/sale_order.py +++ b/mis_builder_cash_flow_forecast_sale/models/sale_order.py @@ -35,13 +35,14 @@ class SaleOrder(models.Model): "currency_id", "order_line.invoice_lines", "order_line.qty_invoiced", + "invoice_ids", ) def _compute_forecast_uninvoiced_amount(self): for order in self: amount_invoiced = sum( x.amount_total for x in order.invoice_ids.filtered( - lambda x: x.state in ["open", "in_payment", "paid"] + lambda x: x.state in ["draft", "posted"] ) ) forecast_uninvoiced_amount = order.amount_total - amount_invoiced @@ -88,18 +89,20 @@ def _compute_payment_terms(self, date, total_balance, total_amount_currency): to_pay_invoice_currency, due_date>. """ if self.payment_term_id: - to_compute = self.payment_term_id.compute(total_balance, date_ref=date) + to_compute = self.payment_term_id.compute( + total_balance, date_ref=date, currency=self.company_id.currency_id + ) if self.currency_id == self.company_id.currency_id: # Single-currency. - return [(b[0], b[1], b[1]) for b in to_compute[0]] + return [(b[0], b[1], b[1]) for b in to_compute] else: # Multi-currencies. to_compute_currency = self.payment_term_id.compute( - total_amount_currency, date_ref=date + total_amount_currency, date_ref=date, currency=self.currency_id ) return [ (b[0], b[1], ac[1]) - for b, ac in zip(to_compute[0], to_compute_currency[0]) + for b, ac in zip(to_compute, to_compute_currency) ] else: return [(fields.Date.to_string(date), total_balance, total_amount_currency)] @@ -167,11 +170,18 @@ def _prepare_mis_cash_flow_forecast_line( parent_res_id = self parent_res_model_id = self.env["ir.model"]._get(parent_res_id._name) - partner = self.partner_id.with_context(force_company=self.company_id.id) + # partner = self.partner_id.with_context(force_company=self.company_id.id) + # + # account_id = partner.property_account_receivable_id or self.env[ + # "ir.property" + # ].get("property_account_receivable_id", "res.partner") - account_id = partner.property_account_receivable_id or self.env[ - "ir.property" - ].get("property_account_receivable_id", "res.partner") + account_id = ( + self.partner_id.property_account_receivable_id.id + or self.env["ir.property"] + ._get("property_account_receivable_id", "res.partner") + .id + ) return { "name": "%s - %s/%s" @@ -181,7 +191,7 @@ def _prepare_mis_cash_flow_forecast_line( payment_term_count, ), "date": date, - "account_id": account_id.id, + "account_id": account_id, "partner_id": self.partner_id.id, "balance": amount, "company_id": self.company_id.id, @@ -248,7 +258,6 @@ def cron_mis_cash_flow_generate_forecast_lines(self): break offset += 100 - @api.multi def action_show_mis_forecast(self): self.ensure_one() context = dict(self.env.context) diff --git a/mis_builder_cash_flow_forecast_sale/static/description/index.html b/mis_builder_cash_flow_forecast_sale/static/description/index.html new file mode 100644 index 0000000..3db5f1c --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/static/description/index.html @@ -0,0 +1,421 @@ + + + + + + +Mis Builder Cash Flow Forecast Sale + + + +
+

Mis Builder Cash Flow Forecast Sale

+ + +

Beta License: AGPL-3 OCA/account-addons Translate me on Weblate

+

Table of contents

+ +
+

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.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Escodoo
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

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.

+

This module is part of the OCA/account-addons project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + From 45951f3823f4ea7aa000f899e700b0782447161b Mon Sep 17 00:00:00 2001 From: oca-ci Date: Wed, 30 Oct 2024 11:52:20 +0000 Subject: [PATCH 15/19] [UPD] Update mis_builder_cash_flow_forecast_sale.pot --- .../mis_builder_cash_flow_forecast_sale.pot | 130 ++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 mis_builder_cash_flow_forecast_sale/i18n/mis_builder_cash_flow_forecast_sale.pot diff --git a/mis_builder_cash_flow_forecast_sale/i18n/mis_builder_cash_flow_forecast_sale.pot b/mis_builder_cash_flow_forecast_sale/i18n/mis_builder_cash_flow_forecast_sale.pot new file mode 100644 index 0000000..0dc1a95 --- /dev/null +++ b/mis_builder_cash_flow_forecast_sale/i18n/mis_builder_cash_flow_forecast_sale.pot @@ -0,0 +1,130 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * mis_builder_cash_flow_forecast_sale +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: mis_builder_cash_flow_forecast_sale +#: model_terms:ir.ui.view,arch_db:mis_builder_cash_flow_forecast_sale.res_config_settings_view_form +msgid "" +"" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model_terms:ir.ui.view,arch_db:mis_builder_cash_flow_forecast_sale.view_order_form +msgid "" +"Cash Flow Forecast\n" +" " +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: code:addons/mis_builder_cash_flow_forecast_sale/models/sale_order.py:0 +#, python-format +msgid "Cash Flow Forecast - Sale" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model,name:mis_builder_cash_flow_forecast_sale.model_res_company +msgid "Companies" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model,name:mis_builder_cash_flow_forecast_sale.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_account_move__display_name +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_res_company__display_name +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_res_config_settings__display_name +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order__display_name +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order_line__display_name +msgid "Display Name" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_res_company__enable_sale_mis_cash_flow_forecast +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_res_config_settings__enable_sale_mis_cash_flow_forecast +msgid "Enable MIS Builder Cash Flow Forecast - Sale" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model_terms:ir.ui.view,arch_db:mis_builder_cash_flow_forecast_sale.res_config_settings_view_form +msgid "Enable MIS Builder Cash Flow Gernerate Sale Forecast" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order__mis_cash_flow_forecast_line_ids +msgid "Forecast Line" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order__mis_cash_flow_forecast_line_count +msgid "Forecast Line Count" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order__forecast_uninvoiced_amount +msgid "Forecast Uninvoiced Amount" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_account_move__id +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_res_company__id +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_res_config_settings__id +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order__id +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order_line__id +msgid "ID" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model,name:mis_builder_cash_flow_forecast_sale.model_account_move +msgid "Journal Entry" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_account_move____last_update +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_res_company____last_update +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_res_config_settings____last_update +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order____last_update +#: model:ir.model.fields,field_description:mis_builder_cash_flow_forecast_sale.field_sale_order_line____last_update +msgid "Last Modified on" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.actions.server,name:mis_builder_cash_flow_forecast_sale.cron_mis_cash_flow_generate_forecast_lines_ir_actions_server +#: model:ir.cron,cron_name:mis_builder_cash_flow_forecast_sale.cron_mis_cash_flow_generate_forecast_lines +#: model:ir.cron,name:mis_builder_cash_flow_forecast_sale.cron_mis_cash_flow_generate_forecast_lines +msgid "MIS Builder Cash Flow - Generate Forecast - Sale Order" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model_terms:ir.ui.view,arch_db:mis_builder_cash_flow_forecast_sale.view_order_form +msgid "MIS Builder Cash Flow Forecast" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model,name:mis_builder_cash_flow_forecast_sale.model_sale_order +msgid "Sales Order" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model:ir.model,name:mis_builder_cash_flow_forecast_sale.model_sale_order_line +msgid "Sales Order Line" +msgstr "" + +#. module: mis_builder_cash_flow_forecast_sale +#: model_terms:ir.ui.view,arch_db:mis_builder_cash_flow_forecast_sale.view_order_tree +msgid "Total Forecast Uninvoiced Amount" +msgstr "" From e04bf4ee823a378d271f1829935f68319ede3eaa Mon Sep 17 00:00:00 2001 From: Wesley Oliveira Date: Mon, 31 Mar 2025 10:54:46 -0300 Subject: [PATCH 16/19] Updated from template --- .../README.rst | 36 +++++-------- .../static/description/index.html | 51 +++++++++---------- 2 files changed, 37 insertions(+), 50 deletions(-) diff --git a/mis_builder_cash_flow_forecast_sale/README.rst b/mis_builder_cash_flow_forecast_sale/README.rst index 23618c8..9aa495d 100644 --- a/mis_builder_cash_flow_forecast_sale/README.rst +++ b/mis_builder_cash_flow_forecast_sale/README.rst @@ -2,10 +2,13 @@ Mis Builder Cash Flow Forecast Sale =================================== -.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:f4b5b7796902a87631304fe7057f4a6cab7707472417788cc1a2ab21234e5e34 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status @@ -13,14 +16,11 @@ Mis Builder Cash Flow Forecast Sale .. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :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--addons-lightgray.png?logo=github - :target: https://github.com/OCA/account-addons/tree/14.0/mis_builder_cash_flow_forecast_sale - :alt: OCA/account-addons -.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/account-addons-14-0/account-addons-14-0-mis_builder_cash_flow_forecast_sale - :alt: Translate me on Weblate +.. |badge3| image:: https://img.shields.io/badge/github-Escodoo%2Faccount--addons-lightgray.png?logo=github + :target: https://github.com/Escodoo/account-addons/tree/14.0/mis_builder_cash_flow_forecast_sale + :alt: Escodoo/account-addons -|badge1| |badge2| |badge3| |badge4| +|badge1| |badge2| |badge3| **Table of contents** @@ -31,10 +31,10 @@ Mis Builder Cash Flow Forecast Sale Bug Tracker =========== -Bugs are tracked on `GitHub Issues `_. +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. @@ -56,16 +56,6 @@ Contributors Maintainers ~~~~~~~~~~~ -This module is maintained by the OCA. - -.. image:: https://odoo-community.org/logo.png - :alt: Odoo Community Association - :target: https://odoo-community.org - -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. - -This module is part of the `OCA/account-addons `_ project on GitHub. +This module is part of the `Escodoo/account-addons `_ project on GitHub. -You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. +You are welcome to contribute. diff --git a/mis_builder_cash_flow_forecast_sale/static/description/index.html b/mis_builder_cash_flow_forecast_sale/static/description/index.html index 3db5f1c..67e5f79 100644 --- a/mis_builder_cash_flow_forecast_sale/static/description/index.html +++ b/mis_builder_cash_flow_forecast_sale/static/description/index.html @@ -1,20 +1,20 @@ - - + Mis Builder Cash Flow Forecast Sale