From ed94f2b9af41889fa835f69a3504a09aa50f453d Mon Sep 17 00:00:00 2001
From: mymage
Date: Fri, 15 Mar 2024 13:20:48 +0000
Subject: [PATCH 01/12] Translated using Weblate (Italian)
Currently translated at 100.0% (229 of 229 strings)
Translation: purchase-workflow-17.0/purchase-workflow-17.0-purchase_request
Translate-URL: https://translation.odoo-community.org/projects/purchase-workflow-17-0/purchase-workflow-17-0-purchase_request/it/
---
procurement_purchase_no_grouping/i18n/it.po | 8 ++-
purchase_request/i18n/it.po | 66 ++++++++++-----------
2 files changed, 40 insertions(+), 34 deletions(-)
diff --git a/procurement_purchase_no_grouping/i18n/it.po b/procurement_purchase_no_grouping/i18n/it.po
index 1f6d9d0ee8c..ac26d454dce 100644
--- a/procurement_purchase_no_grouping/i18n/it.po
+++ b/procurement_purchase_no_grouping/i18n/it.po
@@ -9,7 +9,7 @@ msgstr ""
"Project-Id-Version: Odoo Server 10.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-11-24 07:53+0000\n"
-"PO-Revision-Date: 2024-03-05 14:35+0000\n"
+"PO-Revision-Date: 2024-03-18 09:37+0000\n"
"Last-Translator: mymage \n"
"Language-Team: Italian (https://www.transifex.com/oca/teams/23907/it/)\n"
"Language: it\n"
@@ -29,6 +29,12 @@ msgid ""
"role=\"img\">\n"
" "
msgstr ""
+"Raggruppamento\n"
+" \n"
+" "
#. module: procurement_purchase_no_grouping
#: model:ir.model,name:procurement_purchase_no_grouping.model_res_company
diff --git a/purchase_request/i18n/it.po b/purchase_request/i18n/it.po
index 6d7caa4296c..0c997922021 100644
--- a/purchase_request/i18n/it.po
+++ b/purchase_request/i18n/it.po
@@ -12,7 +12,7 @@ msgstr ""
"Project-Id-Version: purchase-workflow (10.0)\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2016-11-17 03:38+0000\n"
-"PO-Revision-Date: 2024-02-14 16:40+0000\n"
+"PO-Revision-Date: 2024-03-19 18:37+0000\n"
"Last-Translator: mymage \n"
"Language-Team: Italian (http://www.transifex.com/oca/"
"OCA-purchase-workflow-10-0/language/it/)\n"
@@ -124,13 +124,13 @@ msgid ""
"Request Reference:\n"
" "
msgstr ""
-"Riferimento Richiesta:\n"
+"Riferimento richiesta:\n"
" "
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.report_purchase_request
msgid "Requested Date"
-msgstr "Data Richiesta"
+msgstr "Data richiesta"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.report_purchase_request
@@ -162,7 +162,7 @@ msgid ""
" a certain quantity of materials services, so that they are\n"
" available at a certain point in time."
msgstr ""
-"Una richiesta di acquisto è un'istruzione all'Acquisto per procurarsi\n"
+"Una richiesta di acquisto è un'istruzione all'ufficio acquisti di procurare\n"
" una determinata quantità di servizi materiali, in modo che "
"siano\n"
" disponibili in un determinato momento."
@@ -317,8 +317,8 @@ msgid ""
"Check this box to generate Purchase Request instead of generating Requests "
"For Quotation from procurement."
msgstr ""
-"Selezionare questa casella per generare una Richiesta d'Acquisto invece di "
-"generare Richieste di Preventivo dall'approvvigionamento."
+"Selezionare questa casella per generare una richiesta di acquisto invece di "
+"generare richieste di preventivo dall'approvvigionamento."
#. module: purchase_request
#: model_terms:ir.actions.act_window,help:purchase_request.purchase_request_form_action
@@ -352,12 +352,12 @@ msgstr "Copia le descrizioni in un nuovo ordine d'acquisto"
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_form
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_line_make_purchase_order
msgid "Create RFQ"
-msgstr "Crea Richiesta di preventivo"
+msgstr "Crea RdP"
#. module: purchase_request
#: model:ir.model.fields,field_description:purchase_request.field_stock_move__created_purchase_request_line_id
msgid "Created Purchase Request Line"
-msgstr "Linea Richiesta d'Acquisto Creata"
+msgstr "Riga richiesta di acquisto creata"
#. module: purchase_request
#: model:ir.model.fields,field_description:purchase_request.field_purchase_request__create_uid
@@ -460,8 +460,8 @@ msgstr "Costo Stimato"
#: model:ir.model.fields,help:purchase_request.field_purchase_request_line__estimated_cost
msgid "Estimated cost of Purchase Request Line, not propagated to PO."
msgstr ""
-"Costo stimato della Riga della Richiesta d'Acquisto, non esteso all'Ordine "
-"d'Acquisto."
+"Costo stimato della riga della richiesta di acquisto, non esteso all'ordine "
+"di acquisto."
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_line_make_purchase_order
@@ -847,14 +847,14 @@ msgstr "Richiesta di acquisto"
#: code:addons/purchase_request/models/purchase_order.py:0
#, python-format
msgid "Purchase Request %s has already been completed"
-msgstr "La Richiesta di Acquisto %s è già stata completata"
+msgstr "La richiesta di acquisto %s è già stata completata"
#. module: purchase_request
#. odoo-python
#: code:addons/purchase_request/wizard/purchase_request_line_make_purchase_order.py:0
#, python-format
msgid "Purchase Request %s is not approved"
-msgstr "La Richiesta d'Acquisto %s non è approvata"
+msgstr "La richiesta di acquisto %s non è approvata"
#. module: purchase_request
#: model:ir.model,name:purchase_request.model_purchase_request_allocation
@@ -862,12 +862,12 @@ msgstr "La Richiesta d'Acquisto %s non è approvata"
#: model:ir.model.fields,field_description:purchase_request.field_purchase_request_line__purchase_request_allocation_ids
#: model:ir.model.fields,field_description:purchase_request.field_stock_move__purchase_request_allocation_ids
msgid "Purchase Request Allocation"
-msgstr "Allocazione Richiesta d'Acquisto"
+msgstr "Allocazione richiesta di acquisto"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.view_move_form
msgid "Purchase Request Allocations"
-msgstr "Allocazioni Richiesta d'Acquisto"
+msgstr "Allocazioni richiesta di acquisto"
#. module: purchase_request
#: model:ir.model,name:purchase_request.model_purchase_request_line
@@ -875,7 +875,7 @@ msgstr "Allocazioni Richiesta d'Acquisto"
#: model:ir.model.fields,field_description:purchase_request.field_purchase_request_line_make_purchase_order_item__line_id
#: model_terms:ir.ui.view,arch_db:purchase_request.purchase_request_line_form
msgid "Purchase Request Line"
-msgstr "Linea Richiesta d'Acquisto"
+msgstr "Riga richiesta di acquisto"
#. module: purchase_request
#: model:ir.model,name:purchase_request.model_purchase_request_line_make_purchase_order
@@ -903,45 +903,45 @@ msgstr "Conteggio righe richiesta di acquisto"
#: model_terms:ir.ui.view,arch_db:purchase_request.purchase_order_line_form2_sub
#, python-format
msgid "Purchase Request Lines"
-msgstr "Linee Richiesta d'Acquisto"
+msgstr "Righe richieste di acquisto"
#. module: purchase_request
#: model:res.groups,name:purchase_request.group_purchase_request_manager
msgid "Purchase Request Manager"
-msgstr "Manager Richiesta d'Acquisto"
+msgstr "Responsabile richiesta di acquisto"
#. module: purchase_request
#: model:res.groups,name:purchase_request.group_purchase_request_user
msgid "Purchase Request User"
-msgstr "Utente Richiesta d'Acquisto"
+msgstr "Utente richiesta di acquisto"
#. module: purchase_request
#: model:mail.message.subtype,description:purchase_request.mt_request_approved
#: model:mail.message.subtype,name:purchase_request.mt_request_approved
msgid "Purchase Request approved"
-msgstr "Richiesta d'Acquisto approvata"
+msgstr "Richiesta di acquisto approvata"
#. module: purchase_request
#: model:mail.message.subtype,name:purchase_request.mt_request_done
msgid "Purchase Request done"
-msgstr "Richiesta Acquisto completata"
+msgstr "Richiesta di acquisto completata"
#. module: purchase_request
#: model:mail.message.subtype,description:purchase_request.mt_request_done
msgid "Purchase Request is done"
-msgstr "La Richiesta d'Acquisto è completata"
+msgstr "La richiesta di acquisto è completata"
#. module: purchase_request
#: model:mail.message.subtype,description:purchase_request.mt_request_rejected
#: model:mail.message.subtype,name:purchase_request.mt_request_rejected
msgid "Purchase Request rejected"
-msgstr "Richiesta d'Acquisto rifiutata"
+msgstr "Richiesta di acquisto rifiutata"
#. module: purchase_request
#: model:mail.message.subtype,description:purchase_request.mt_request_to_approve
#: model:mail.message.subtype,name:purchase_request.mt_request_to_approve
msgid "Purchase Request to be approved"
-msgstr "Richiesta d'Acquisto in approvazione"
+msgstr "Richiesta di acquisto da approvare"
#. module: purchase_request
#: model:ir.actions.act_window,name:purchase_request.action_purchase_request_line_product_tree
@@ -952,7 +952,7 @@ msgstr "Richiesta d'Acquisto in approvazione"
#: model:ir.ui.menu,name:purchase_request.menu_purchase_request_pro_mgt
#: model:ir.ui.menu,name:purchase_request.parent_menu_purchase_request
msgid "Purchase Requests"
-msgstr "Richieste d'Acquisto"
+msgstr "Richieste di acquisto"
#. module: purchase_request
#: model:ir.model.fields,field_description:purchase_request.field_purchase_request_line__purchase_state
@@ -1053,7 +1053,7 @@ msgstr ""
#: code:addons/purchase_request/models/stock_move_line.py:0
#, python-format
msgid "Receipt confirmation for Request %s"
-msgstr "Ricevuta di conferma per la Richiesta %s"
+msgstr "Ricevuta di conferma per la richiesta %s"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_form
@@ -1086,18 +1086,18 @@ msgstr "Righe richiesta"
#. module: purchase_request
#: model:ir.model.fields,field_description:purchase_request.field_purchase_request__name
msgid "Request Reference"
-msgstr "Riferimento Richiesta"
+msgstr "Riferimento richiesta"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_form
msgid "Request approval"
-msgstr "Approvazione Richiesta"
+msgstr "Approvazione richiesta"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.purchase_request_line_search
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_search
msgid "Request is approved"
-msgstr "La Richiesta è approvata"
+msgstr "La richiesta è approvata"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_search
@@ -1108,13 +1108,13 @@ msgstr "La richiesta è completata"
#: model_terms:ir.ui.view,arch_db:purchase_request.purchase_request_line_search
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_search
msgid "Request is rejected"
-msgstr "La Richiesta è rifiutata"
+msgstr "La richiesta è rifiutata"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.purchase_request_line_search
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_search
msgid "Request is to be approved"
-msgstr "La Richiesta è in approvazione"
+msgstr "La richiesta è in approvazione"
#. module: purchase_request
#: model:ir.model.fields,field_description:purchase_request.field_purchase_request_line__request_state
@@ -1124,7 +1124,7 @@ msgstr "Stato richiesta"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.purchase_request_line_search
msgid "Request status"
-msgstr "Stato Richiesta"
+msgstr "Stato richiesta"
#. module: purchase_request
#: model:ir.model.fields,field_description:purchase_request.field_purchase_request__requested_by
@@ -1146,7 +1146,7 @@ msgstr "Richiesta da"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.purchase_request_line_search
msgid "Requested for Quotation"
-msgstr "Richiesta Offerta"
+msgstr "Richiesta per offerta"
#. module: purchase_request
#: model_terms:ir.ui.view,arch_db:purchase_request.view_purchase_request_form
@@ -1496,7 +1496,7 @@ msgstr "Bisogna selezionare le righe dallo stesso tipo di prelievo."
#: code:addons/purchase_request/wizard/purchase_request_line_make_purchase_order.py:0
#, python-format
msgid "You have to select lines from the same company."
-msgstr "Devi selezionare le righe della stessa azienda."
+msgstr "Bisogna selezionare le righe della stessa azienda."
#~ msgid "Last Modified on"
#~ msgstr "Ultima modifica il"
From 79042dbca78231488184c95e057b720208fe0459 Mon Sep 17 00:00:00 2001
From: Mateu Griful
Date: Tue, 13 Jul 2021 15:46:42 +0200
Subject: [PATCH 02/12] [ADD] purchase_advance_payment
---
purchase_advance_payment/__init__.py | 2 +
purchase_advance_payment/__manifest__.py | 19 ++
purchase_advance_payment/models/__init__.py | 2 +
purchase_advance_payment/models/payment.py | 16 ++
.../models/purchase_order.py | 86 +++++++
.../readme/CONTRIBUTORS.rst | 2 +
.../readme/DESCRIPTION.rst | 3 +
purchase_advance_payment/readme/USAGE.rst | 8 +
.../security/ir.model.access.csv | 4 +
purchase_advance_payment/tests/__init__.py | 1 +
.../tests/test_purchase_advance_payment.py | 218 ++++++++++++++++++
.../views/purchase_view.xml | 96 ++++++++
purchase_advance_payment/wizard/__init__.py | 1 +
.../wizard/purchase_advance_payment_wizard.py | 128 ++++++++++
.../purchase_advance_payment_wizard_view.xml | 53 +++++
15 files changed, 639 insertions(+)
create mode 100644 purchase_advance_payment/__init__.py
create mode 100644 purchase_advance_payment/__manifest__.py
create mode 100644 purchase_advance_payment/models/__init__.py
create mode 100644 purchase_advance_payment/models/payment.py
create mode 100644 purchase_advance_payment/models/purchase_order.py
create mode 100644 purchase_advance_payment/readme/CONTRIBUTORS.rst
create mode 100644 purchase_advance_payment/readme/DESCRIPTION.rst
create mode 100644 purchase_advance_payment/readme/USAGE.rst
create mode 100644 purchase_advance_payment/security/ir.model.access.csv
create mode 100644 purchase_advance_payment/tests/__init__.py
create mode 100644 purchase_advance_payment/tests/test_purchase_advance_payment.py
create mode 100644 purchase_advance_payment/views/purchase_view.xml
create mode 100644 purchase_advance_payment/wizard/__init__.py
create mode 100644 purchase_advance_payment/wizard/purchase_advance_payment_wizard.py
create mode 100644 purchase_advance_payment/wizard/purchase_advance_payment_wizard_view.xml
diff --git a/purchase_advance_payment/__init__.py b/purchase_advance_payment/__init__.py
new file mode 100644
index 00000000000..9b4296142f4
--- /dev/null
+++ b/purchase_advance_payment/__init__.py
@@ -0,0 +1,2 @@
+from . import models
+from . import wizard
diff --git a/purchase_advance_payment/__manifest__.py b/purchase_advance_payment/__manifest__.py
new file mode 100644
index 00000000000..01e76a79c09
--- /dev/null
+++ b/purchase_advance_payment/__manifest__.py
@@ -0,0 +1,19 @@
+# Copyright (C) 2021 ForgeFlow S.L.
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
+
+{
+ "name": "Purchase Advance Payment",
+ "version": "14.0.1.0.0",
+ "author": "Forgeflow, Odoo Community Association (OCA)",
+ "website": "https://github.com/OCA/purchase-workflow",
+ "category": "Purchase",
+ "license": "AGPL-3",
+ "summary": "Allow to add advance payments on purchase orders",
+ "depends": ["purchase"],
+ "data": [
+ "wizard/purchase_advance_payment_wizard_view.xml",
+ "views/purchase_view.xml",
+ "security/ir.model.access.csv",
+ ],
+ "installable": True,
+}
diff --git a/purchase_advance_payment/models/__init__.py b/purchase_advance_payment/models/__init__.py
new file mode 100644
index 00000000000..2a7a713d96d
--- /dev/null
+++ b/purchase_advance_payment/models/__init__.py
@@ -0,0 +1,2 @@
+from . import payment
+from . import purchase_order
diff --git a/purchase_advance_payment/models/payment.py b/purchase_advance_payment/models/payment.py
new file mode 100644
index 00000000000..3b6473ed6af
--- /dev/null
+++ b/purchase_advance_payment/models/payment.py
@@ -0,0 +1,16 @@
+# Copyright (C) 2021 ForgeFlow S.L.
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
+
+from odoo import fields, models
+
+
+class AccountPayment(models.Model):
+
+ _inherit = "account.payment"
+
+ purchase_id = fields.Many2one(
+ "purchase.order",
+ "Purchase",
+ readonly=True,
+ states={"draft": [("readonly", False)]},
+ )
diff --git a/purchase_advance_payment/models/purchase_order.py b/purchase_advance_payment/models/purchase_order.py
new file mode 100644
index 00000000000..e4f025d669e
--- /dev/null
+++ b/purchase_advance_payment/models/purchase_order.py
@@ -0,0 +1,86 @@
+# Copyright (C) 2021 ForgeFlow S.L.
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
+
+from odoo import api, fields, models
+from odoo.tools import float_compare
+
+
+class PurchaseOrder(models.Model):
+
+ _inherit = "purchase.order"
+
+ account_payment_ids = fields.One2many(
+ "account.payment", "purchase_id", string="Pay purchase advanced", readonly=True
+ )
+ amount_residual = fields.Float(
+ "Residual amount",
+ readonly=True,
+ compute="_compute_purchase_advance_payment",
+ store=True,
+ )
+ payment_line_ids = fields.Many2many(
+ "account.move.line",
+ string="Payment move lines",
+ compute="_compute_purchase_advance_payment",
+ store=True,
+ )
+ advance_payment_status = fields.Selection(
+ selection=[
+ ("not_paid", "Not Paid"),
+ ("paid", "Paid"),
+ ("partial", "Partially Paid"),
+ ],
+ string="Advance Payment Status",
+ store=True,
+ readonly=True,
+ copy=False,
+ tracking=True,
+ compute="_compute_purchase_advance_payment",
+ )
+
+ @api.depends(
+ "currency_id",
+ "company_id",
+ "amount_total",
+ "account_payment_ids",
+ "account_payment_ids.state",
+ "account_payment_ids.move_id",
+ "account_payment_ids.move_id.line_ids",
+ "account_payment_ids.move_id.line_ids.date",
+ "account_payment_ids.move_id.line_ids.debit",
+ "account_payment_ids.move_id.line_ids.credit",
+ "account_payment_ids.move_id.line_ids.currency_id",
+ "account_payment_ids.move_id.line_ids.amount_currency",
+ )
+ def _compute_purchase_advance_payment(self):
+ for order in self:
+ mls = order.account_payment_ids.mapped("move_id.line_ids").filtered(
+ lambda x: x.account_id.internal_type == "payable"
+ and x.parent_state == "posted"
+ )
+ advance_amount = 0.0
+ for line in mls:
+ line_currency = line.currency_id or line.company_id.currency_id
+ line_amount = line.amount_currency if line.currency_id else line.balance
+ if line_currency != order.currency_id:
+ advance_amount += line.currency_id._convert(
+ line_amount,
+ order.currency_id,
+ order.company_id,
+ line.date or fields.Date.today(),
+ )
+ else:
+ advance_amount += line_amount
+ amount_residual = order.amount_total - advance_amount
+ payment_state = "not_paid"
+ if mls:
+ has_due_amount = float_compare(
+ amount_residual, 0.0, precision_rounding=order.currency_id.rounding
+ )
+ if has_due_amount <= 0:
+ payment_state = "paid"
+ elif has_due_amount > 0:
+ payment_state = "partial"
+ order.payment_line_ids = mls
+ order.amount_residual = amount_residual
+ order.advance_payment_status = payment_state
diff --git a/purchase_advance_payment/readme/CONTRIBUTORS.rst b/purchase_advance_payment/readme/CONTRIBUTORS.rst
new file mode 100644
index 00000000000..087dd29233f
--- /dev/null
+++ b/purchase_advance_payment/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
+* Mateu Griful
+* Lois Rilo
diff --git a/purchase_advance_payment/readme/DESCRIPTION.rst b/purchase_advance_payment/readme/DESCRIPTION.rst
new file mode 100644
index 00000000000..2509a323453
--- /dev/null
+++ b/purchase_advance_payment/readme/DESCRIPTION.rst
@@ -0,0 +1,3 @@
+The module allows to add advance payments on purchase orders and Request
+for Quotation. The advance payments are allowed even before confirmation
+and before starting the billing process.
diff --git a/purchase_advance_payment/readme/USAGE.rst b/purchase_advance_payment/readme/USAGE.rst
new file mode 100644
index 00000000000..df9904e8b23
--- /dev/null
+++ b/purchase_advance_payment/readme/USAGE.rst
@@ -0,0 +1,8 @@
+To use this module, you need to:
+
+* Go to a purchase order.
+* Click on "Pay Purchase Advance".
+* Select the Journal and specify the amount of the advanced payment.
+* "Make Advance Payment".
+
+When generating the invoice, the system displays the advanced payments, select those you want to add to the invoice.
diff --git a/purchase_advance_payment/security/ir.model.access.csv b/purchase_advance_payment/security/ir.model.access.csv
new file mode 100644
index 00000000000..a432eb67dbf
--- /dev/null
+++ b/purchase_advance_payment/security/ir.model.access.csv
@@ -0,0 +1,4 @@
+id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
+access_account_payment_purchase_advance,account.payment purchase_advance,account.model_account_payment,purchase.group_purchase_user,1,1,1,0
+access_account_payment_method_purchase_advance,account.payment.method purchase_advance,account.model_account_payment_method,purchase.group_purchase_user,1,0,0,0
+access_account_voucher_wizard_purchase_advance,access_account_voucher_wizard_purchase_advance,model_account_voucher_wizard_purchase,purchase.group_purchase_user,1,1,1,0
diff --git a/purchase_advance_payment/tests/__init__.py b/purchase_advance_payment/tests/__init__.py
new file mode 100644
index 00000000000..beeea01aff5
--- /dev/null
+++ b/purchase_advance_payment/tests/__init__.py
@@ -0,0 +1 @@
+from . import test_purchase_advance_payment
diff --git a/purchase_advance_payment/tests/test_purchase_advance_payment.py b/purchase_advance_payment/tests/test_purchase_advance_payment.py
new file mode 100644
index 00000000000..665a9cf21de
--- /dev/null
+++ b/purchase_advance_payment/tests/test_purchase_advance_payment.py
@@ -0,0 +1,218 @@
+# Copyright (C) 2021 ForgeFlow S.L.
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
+
+
+from odoo.exceptions import ValidationError
+from odoo.tests import common
+
+
+class TestPurchaseAdvancePayment(common.SavepointCase):
+ @classmethod
+ def setUpClass(cls):
+ super().setUpClass()
+
+ # Partners
+ cls.res_partner_1 = cls.env["res.partner"].create({"name": "Wood Corner"})
+ cls.res_partner_address_1 = cls.env["res.partner"].create(
+ {"name": "Willie Burke", "parent_id": cls.res_partner_1.id}
+ )
+ cls.res_partner_2 = cls.env["res.partner"].create({"name": "Partner 12"})
+
+ # Products
+ cls.product_1 = cls.env["product.product"].create(
+ {"name": "Desk Combination", "type": "consu", "purchase_method": "purchase"}
+ )
+ cls.product_2 = cls.env["product.product"].create(
+ {"name": "Conference Chair", "type": "consu", "purchase_method": "purchase"}
+ )
+ cls.product_3 = cls.env["product.product"].create(
+ {
+ "name": "Repair Services",
+ "type": "service",
+ "purchase_method": "purchase",
+ }
+ )
+
+ cls.tax = cls.env["account.tax"].create(
+ {
+ "name": "Tax 20",
+ "type_tax_use": "purchase",
+ "amount": 20,
+ }
+ )
+
+ # purchase Order
+ cls.purchase_order_1 = cls.env["purchase.order"].create(
+ {"partner_id": cls.res_partner_1.id}
+ )
+ cls.order_line_1 = cls.env["purchase.order.line"].create(
+ {
+ "order_id": cls.purchase_order_1.id,
+ "product_id": cls.product_1.id,
+ "product_uom": cls.product_1.uom_id.id,
+ "product_qty": 10.0,
+ "price_unit": 100.0,
+ "taxes_id": cls.tax,
+ }
+ )
+ cls.order_line_2 = cls.env["purchase.order.line"].create(
+ {
+ "order_id": cls.purchase_order_1.id,
+ "product_id": cls.product_2.id,
+ "product_uom": cls.product_2.uom_id.id,
+ "product_qty": 25.0,
+ "price_unit": 40.0,
+ "taxes_id": cls.tax,
+ }
+ )
+ cls.order_line_3 = cls.env["purchase.order.line"].create(
+ {
+ "order_id": cls.purchase_order_1.id,
+ "product_id": cls.product_3.id,
+ "product_uom": cls.product_3.uom_id.id,
+ "product_qty": 20.0,
+ "price_unit": 50.0,
+ "taxes_id": cls.tax,
+ }
+ )
+
+ cls.currency_euro = cls.env["res.currency"].search([("name", "=", "EUR")])
+ cls.currency_usd = cls.env["res.currency"].search([("name", "=", "USD")])
+ cls.currency_rate = cls.env["res.currency.rate"].create(
+ {
+ "rate": 1.20,
+ "currency_id": cls.currency_usd.id,
+ }
+ )
+
+ cls.journal_eur_bank = cls.env["account.journal"].create(
+ {
+ "name": "Journal Euro Bank",
+ "type": "bank",
+ "code": "111",
+ "currency_id": cls.currency_euro.id,
+ }
+ )
+
+ cls.journal_usd_bank = cls.env["account.journal"].create(
+ {
+ "name": "Journal USD Bank",
+ "type": "bank",
+ "code": "222",
+ "currency_id": cls.currency_usd.id,
+ }
+ )
+ cls.journal_eur_cash = cls.env["account.journal"].create(
+ {
+ "name": "Journal Euro Cash",
+ "type": "cash",
+ "code": "333",
+ "currency_id": cls.currency_euro.id,
+ }
+ )
+
+ cls.journal_usd_cash = cls.env["account.journal"].create(
+ {
+ "name": "Journal USD Cash",
+ "type": "cash",
+ "code": "444",
+ "currency_id": cls.currency_usd.id,
+ }
+ )
+
+ def test_purchase_advance_payment(self):
+ self.assertEqual(
+ self.purchase_order_1.amount_residual,
+ 3600,
+ )
+ self.assertEqual(
+ self.purchase_order_1.amount_residual,
+ self.purchase_order_1.amount_total,
+ "Amounts should match",
+ )
+
+ context_payment = {
+ "active_ids": [self.purchase_order_1.id],
+ "active_id": self.purchase_order_1.id,
+ }
+
+ # Check residual > advance payment and the comparison takes
+ # into account the currency. 3001*1.2 > 3600
+ with self.assertRaises(ValidationError):
+ advance_payment_0 = (
+ self.env["account.voucher.wizard.purchase"]
+ .with_context(context_payment)
+ .create(
+ {
+ "journal_id": self.journal_eur_bank.id,
+ "amount_advance": 3001,
+ "order_id": self.purchase_order_1.id,
+ }
+ )
+ )
+ advance_payment_0.make_advance_payment()
+
+ # Create Advance Payment 1 - EUR - bank
+ advance_payment_1 = (
+ self.env["account.voucher.wizard.purchase"]
+ .with_context(context_payment)
+ .create(
+ {
+ "journal_id": self.journal_eur_bank.id,
+ "amount_advance": 100,
+ "order_id": self.purchase_order_1.id,
+ }
+ )
+ )
+ advance_payment_1.make_advance_payment()
+
+ self.assertEqual(self.purchase_order_1.amount_residual, 3480)
+
+ # Create Advance Payment 2 - USD - cash
+ advance_payment_2 = (
+ self.env["account.voucher.wizard.purchase"]
+ .with_context(context_payment)
+ .create(
+ {
+ "journal_id": self.journal_usd_cash.id,
+ "amount_advance": 200,
+ "order_id": self.purchase_order_1.id,
+ }
+ )
+ )
+ advance_payment_2.make_advance_payment()
+
+ self.assertEqual(self.purchase_order_1.amount_residual, 3280)
+
+ # Confirm Purchase Order
+ self.purchase_order_1.button_confirm()
+
+ # Create Advance Payment 3 - EUR - cash
+ advance_payment_3 = (
+ self.env["account.voucher.wizard.purchase"]
+ .with_context(context_payment)
+ .create(
+ {
+ "journal_id": self.journal_eur_cash.id,
+ "amount_advance": 250,
+ "order_id": self.purchase_order_1.id,
+ }
+ )
+ )
+ advance_payment_3.make_advance_payment()
+ self.assertEqual(self.purchase_order_1.amount_residual, 2980)
+
+ # Create Advance Payment 4 - USD - bank
+ advance_payment_4 = (
+ self.env["account.voucher.wizard.purchase"]
+ .with_context(context_payment)
+ .create(
+ {
+ "journal_id": self.journal_usd_bank.id,
+ "amount_advance": 400,
+ "order_id": self.purchase_order_1.id,
+ }
+ )
+ )
+ advance_payment_4.make_advance_payment()
+ self.assertEqual(self.purchase_order_1.amount_residual, 2580)
diff --git a/purchase_advance_payment/views/purchase_view.xml b/purchase_advance_payment/views/purchase_view.xml
new file mode 100644
index 00000000000..44d8e6e9fb8
--- /dev/null
+++ b/purchase_advance_payment/views/purchase_view.xml
@@ -0,0 +1,96 @@
+
+
+
+ purchase.order.form
+ purchase.order
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ purchase.order.view.tree
+ purchase.order
+
+
+
+
+
+
+
+
+
+
+
+
+ purchase.order.inherit.purchase.order.tree
+ purchase.order
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/purchase_advance_payment/wizard/__init__.py b/purchase_advance_payment/wizard/__init__.py
new file mode 100644
index 00000000000..875157a0fda
--- /dev/null
+++ b/purchase_advance_payment/wizard/__init__.py
@@ -0,0 +1 @@
+from . import purchase_advance_payment_wizard
diff --git a/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py b/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py
new file mode 100644
index 00000000000..0ef7fdc4fbd
--- /dev/null
+++ b/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py
@@ -0,0 +1,128 @@
+# Copyright (C) 2021 ForgeFlow S.L.
+# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
+
+from odoo import _, api, exceptions, fields, models
+from odoo.tools import float_compare
+
+
+class AccountVoucherWizardPurchase(models.TransientModel):
+
+ _name = "account.voucher.wizard.purchase"
+ _description = "Account Voucher Wizard Purchase"
+
+ order_id = fields.Many2one("purchase.order", required=True)
+ journal_id = fields.Many2one(
+ "account.journal",
+ "Journal",
+ required=True,
+ domain=[("type", "in", ("bank", "cash"))],
+ )
+ journal_currency_id = fields.Many2one(
+ "res.currency",
+ "Journal Currency",
+ store=True,
+ readonly=False,
+ compute="_compute_get_journal_currency",
+ )
+ currency_id = fields.Many2one("res.currency", "Currency", readonly=True)
+ amount_total = fields.Monetary("Amount total", readonly=True)
+ amount_advance = fields.Monetary(
+ "Amount advanced", required=True, currency_field="journal_currency_id"
+ )
+ date = fields.Date("Date", required=True, default=fields.Date.context_today)
+ currency_amount = fields.Monetary(
+ "Curr. amount", readonly=True, currency_field="currency_id"
+ )
+ payment_ref = fields.Char("Ref.")
+
+ @api.depends("journal_id")
+ def _compute_get_journal_currency(self):
+ for wzd in self:
+ wzd.journal_currency_id = (
+ wzd.journal_id.currency_id.id or self.env.user.company_id.currency_id.id
+ )
+
+ @api.constrains("amount_advance")
+ def check_amount(self):
+ if self.amount_advance <= 0:
+ raise exceptions.ValidationError(_("Amount of advance must be positive."))
+ if self.env.context.get("active_id", False):
+ self.onchange_date()
+ if (
+ float_compare(
+ self.currency_amount,
+ self.order_id.amount_residual,
+ precision_digits=2,
+ )
+ > 0
+ ):
+ raise exceptions.ValidationError(
+ _("Amount of advance is greater than residual amount on purchase")
+ )
+
+ @api.model
+ def default_get(self, fields_list):
+ res = super().default_get(fields_list)
+ purchase_ids = self.env.context.get("active_ids", [])
+ if not purchase_ids:
+ return res
+ purchase_id = fields.first(purchase_ids)
+ purchase = self.env["purchase.order"].browse(purchase_id)
+ if "amount_total" in fields_list:
+ res.update(
+ {
+ "order_id": purchase.id,
+ "amount_total": purchase.amount_residual,
+ "currency_id": purchase.currency_id.id,
+ }
+ )
+
+ return res
+
+ @api.onchange("journal_id", "date", "amount_advance")
+ def onchange_date(self):
+ if self.journal_currency_id != self.currency_id:
+ amount_advance = self.journal_currency_id._convert(
+ self.amount_advance,
+ self.currency_id,
+ self.order_id.company_id,
+ self.date or fields.Date.today(),
+ )
+ else:
+ amount_advance = self.amount_advance
+ self.currency_amount = amount_advance
+
+ def _prepare_payment_vals(self, purchase):
+ partner_id = purchase.partner_id.id
+ return {
+ "date": self.date,
+ "amount": self.amount_advance,
+ "payment_type": "outbound",
+ "partner_type": "supplier",
+ "ref": self.payment_ref or purchase.name,
+ "journal_id": self.journal_id.id,
+ "currency_id": self.journal_currency_id.id,
+ "partner_id": partner_id,
+ "payment_method_id": self.env.ref(
+ "account.account_payment_method_manual_out"
+ ).id,
+ }
+
+ def make_advance_payment(self):
+ """Create customer paylines and validates the payment"""
+ self.ensure_one()
+ payment_obj = self.env["account.payment"]
+ purchase_obj = self.env["purchase.order"]
+
+ purchase_ids = self.env.context.get("active_ids", [])
+ if purchase_ids:
+ purchase_id = fields.first(purchase_ids)
+ purchase = purchase_obj.browse(purchase_id)
+ payment_vals = self._prepare_payment_vals(purchase)
+ payment = payment_obj.create(payment_vals)
+ purchase.account_payment_ids |= payment
+ payment.action_post()
+
+ return {
+ "type": "ir.actions.act_window_close",
+ }
diff --git a/purchase_advance_payment/wizard/purchase_advance_payment_wizard_view.xml b/purchase_advance_payment/wizard/purchase_advance_payment_wizard_view.xml
new file mode 100644
index 00000000000..41c4d5b3f45
--- /dev/null
+++ b/purchase_advance_payment/wizard/purchase_advance_payment_wizard_view.xml
@@ -0,0 +1,53 @@
+
+
+
+ Advance Payment
+ account.voucher.wizard.purchase
+ form
+
+
+
+
+
+ Advance Payment
+ ir.actions.act_window
+ account.voucher.wizard.purchase
+ form
+ new
+
+
From 5b77effc840072be4a580e528c373e2417a7f50b Mon Sep 17 00:00:00 2001
From: Lois Rilo
Date: Wed, 3 Nov 2021 15:11:49 +0100
Subject: [PATCH 03/12] [IMP] purchase_advance_payment: consider payments in PO
bills to compute residual.
---
purchase_advance_payment/README.rst | 88 ++++
.../i18n/purchase_advance_payment.pot | 221 +++++++++
.../models/purchase_order.py | 13 +-
.../static/description/index.html | 434 ++++++++++++++++++
.../tests/test_purchase_advance_payment.py | 52 ++-
.../views/purchase_view.xml | 2 +-
6 files changed, 806 insertions(+), 4 deletions(-)
create mode 100644 purchase_advance_payment/README.rst
create mode 100644 purchase_advance_payment/i18n/purchase_advance_payment.pot
create mode 100644 purchase_advance_payment/static/description/index.html
diff --git a/purchase_advance_payment/README.rst b/purchase_advance_payment/README.rst
new file mode 100644
index 00000000000..dc3ab94c339
--- /dev/null
+++ b/purchase_advance_payment/README.rst
@@ -0,0 +1,88 @@
+========================
+Purchase Advance Payment
+========================
+
+.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ !! 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%2Fpurchase--workflow-lightgray.png?logo=github
+ :target: https://github.com/OCA/purchase-workflow/tree/14.0/purchase_advance_payment
+ :alt: OCA/purchase-workflow
+.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
+ :target: https://translation.odoo-community.org/projects/purchase-workflow-14-0/purchase-workflow-14-0-purchase_advance_payment
+ :alt: Translate me on Weblate
+.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
+ :target: https://runbot.odoo-community.org/runbot/142/14.0
+ :alt: Try me on Runbot
+
+|badge1| |badge2| |badge3| |badge4| |badge5|
+
+The module allows to add advance payments on purchase orders and Request
+for Quotation. The advance payments are allowed even before confirmation
+and before starting the billing process.
+
+**Table of contents**
+
+.. contents::
+ :local:
+
+Usage
+=====
+
+To use this module, you need to:
+
+* Go to a purchase order.
+* Click on "Pay Purchase Advance".
+* Select the Journal and specify the amount of the advanced payment.
+* "Make Advance Payment".
+
+When generating the invoice, the system displays the advanced payments, select those you want to add to the invoice.
+
+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
+~~~~~~~
+
+* Forgeflow
+
+Contributors
+~~~~~~~~~~~~
+
+* Mateu Griful
+* Lois Rilo
+
+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/purchase-workflow `_ project on GitHub.
+
+You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/purchase_advance_payment/i18n/purchase_advance_payment.pot b/purchase_advance_payment/i18n/purchase_advance_payment.pot
new file mode 100644
index 00000000000..38c7beadd7d
--- /dev/null
+++ b/purchase_advance_payment/i18n/purchase_advance_payment.pot
@@ -0,0 +1,221 @@
+# Translation of Odoo Server.
+# This file contains the translation of the following modules:
+# * purchase_advance_payment
+#
+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: purchase_advance_payment
+#: model:ir.model,name:purchase_advance_payment.model_account_voucher_wizard_purchase
+msgid "Account Voucher Wizard Purchase"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.actions.act_window,name:purchase_advance_payment.action_view_account_voucher_wizard
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Advance Payment"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order__advance_payment_status
+msgid "Advance Payment Status"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.purchase_order_kpis_tree
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.purchase_order_view_tree
+msgid "Amount Residual"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__amount_advance
+msgid "Amount advanced"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Amount in Order Currency"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: code:addons/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py:0
+#, python-format
+msgid "Amount of advance is greater than residual amount on purchase"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: code:addons/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py:0
+#, python-format
+msgid "Amount of advance must be positive."
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__amount_total
+msgid "Amount total"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Cancel"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__create_uid
+msgid "Created by"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__create_date
+msgid "Created on"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__currency_amount
+msgid "Curr. amount"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__currency_id
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Currency"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__date
+msgid "Date"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_payment__display_name
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__display_name
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order__display_name
+msgid "Display Name"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_payment__id
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__id
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order__id
+msgid "ID"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__journal_id
+msgid "Journal"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__journal_currency_id
+msgid "Journal Currency"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_payment____last_update
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase____last_update
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order____last_update
+msgid "Last Modified on"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__write_uid
+msgid "Last Updated by"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__write_date
+msgid "Last Updated on"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Make advance payment"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields.selection,name:purchase_advance_payment.selection__purchase_order__advance_payment_status__not_paid
+msgid "Not Paid"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Operation"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__order_id
+msgid "Order"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Order Currency"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Order Due Amount"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields.selection,name:purchase_advance_payment.selection__purchase_order__advance_payment_status__paid
+msgid "Paid"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields.selection,name:purchase_advance_payment.selection__purchase_order__advance_payment_status__partial
+msgid "Partially Paid"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order__account_payment_ids
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.purchase_order_form
+msgid "Pay purchase advanced"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
+msgid "Payment Method"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.purchase_order_form
+msgid "Payment advances"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order__payment_line_ids
+msgid "Payment move lines"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model,name:purchase_advance_payment.model_account_payment
+msgid "Payments"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_payment__purchase_id
+msgid "Purchase"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model,name:purchase_advance_payment.model_purchase_order
+msgid "Purchase Order"
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__payment_ref
+msgid "Ref."
+msgstr ""
+
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order__amount_residual
+msgid "Residual amount"
+msgstr ""
diff --git a/purchase_advance_payment/models/purchase_order.py b/purchase_advance_payment/models/purchase_order.py
index e4f025d669e..b6b5791668a 100644
--- a/purchase_advance_payment/models/purchase_order.py
+++ b/purchase_advance_payment/models/purchase_order.py
@@ -51,6 +51,9 @@ class PurchaseOrder(models.Model):
"account_payment_ids.move_id.line_ids.credit",
"account_payment_ids.move_id.line_ids.currency_id",
"account_payment_ids.move_id.line_ids.amount_currency",
+ "order_line.invoice_lines.move_id",
+ "order_line.invoice_lines.move_id.amount_total",
+ "order_line.invoice_lines.move_id.amount_residual",
)
def _compute_purchase_advance_payment(self):
for order in self:
@@ -71,9 +74,15 @@ def _compute_purchase_advance_payment(self):
)
else:
advance_amount += line_amount
- amount_residual = order.amount_total - advance_amount
+ # Consider payments in related invoices.
+ invoice_not_paid_amount = 0.0
+ for inv in order.invoice_ids:
+ invoice_not_paid_amount += inv.amount_total - inv.amount_residual
+ amount_residual = (
+ order.amount_total - advance_amount - invoice_not_paid_amount
+ )
payment_state = "not_paid"
- if mls:
+ if mls or order.invoice_ids:
has_due_amount = float_compare(
amount_residual, 0.0, precision_rounding=order.currency_id.rounding
)
diff --git a/purchase_advance_payment/static/description/index.html b/purchase_advance_payment/static/description/index.html
new file mode 100644
index 00000000000..bc37d1434d4
--- /dev/null
+++ b/purchase_advance_payment/static/description/index.html
@@ -0,0 +1,434 @@
+
+
+
+
+
+
+Purchase Advance Payment
+
+
+
+
+
Purchase Advance Payment
+
+
+
+
The module allows to add advance payments on purchase orders and Request
+for Quotation. The advance payments are allowed even before confirmation
+and before starting the billing process.
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.
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 file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
The module allows to add advance payments on purchase orders and Request
for Quotation. The advance payments are allowed even before confirmation
and before starting the billing process.
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.
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.
diff --git a/purchase_advance_payment/tests/test_purchase_advance_payment.py b/purchase_advance_payment/tests/test_purchase_advance_payment.py
index 16fd626fb9e..4b66610c48b 100644
--- a/purchase_advance_payment/tests/test_purchase_advance_payment.py
+++ b/purchase_advance_payment/tests/test_purchase_advance_payment.py
@@ -7,7 +7,7 @@
from odoo.tests import common
-class TestPurchaseAdvancePayment(common.SavepointCase):
+class TestPurchaseAdvancePayment(common.TransactionCase):
@classmethod
def setUpClass(cls):
super().setUpClass()
@@ -77,7 +77,16 @@ def setUpClass(cls):
}
)
- cls.currency_euro = cls.env["res.currency"].search([("name", "=", "EUR")])
+ cls.active_euro = False
+ cls.currency_euro = (
+ cls.env["res.currency"]
+ .with_context(active_test=False)
+ .search([("name", "=", "EUR")])
+ )
+ # active euro currency if inactive for test
+ if not cls.currency_euro.active:
+ cls.currency_euro.active = True
+ cls.active_euro = True
cls.currency_usd = cls.env["res.currency"].search([("name", "=", "USD")])
cls.currency_rate = cls.env["res.currency.rate"].create(
{
@@ -142,7 +151,7 @@ def test_01_purchase_advance_payment(self):
with self.assertRaises(ValidationError):
advance_payment_0 = (
self.env["account.voucher.wizard.purchase"]
- .with_context(context_payment)
+ .with_context(**context_payment)
.create(
{
"journal_id": self.journal_eur_bank.id,
@@ -156,7 +165,7 @@ def test_01_purchase_advance_payment(self):
# Create Advance Payment 1 - EUR - bank
advance_payment_1 = (
self.env["account.voucher.wizard.purchase"]
- .with_context(context_payment)
+ .with_context(**context_payment)
.create(
{
"journal_id": self.journal_eur_bank.id,
@@ -172,7 +181,7 @@ def test_01_purchase_advance_payment(self):
# Create Advance Payment 2 - USD - cash
advance_payment_2 = (
self.env["account.voucher.wizard.purchase"]
- .with_context(context_payment)
+ .with_context(**context_payment)
.create(
{
"journal_id": self.journal_usd_cash.id,
@@ -191,7 +200,7 @@ def test_01_purchase_advance_payment(self):
# Create Advance Payment 3 - EUR - cash
advance_payment_3 = (
self.env["account.voucher.wizard.purchase"]
- .with_context(context_payment)
+ .with_context(**context_payment)
.create(
{
"journal_id": self.journal_eur_cash.id,
@@ -206,7 +215,7 @@ def test_01_purchase_advance_payment(self):
# Create Advance Payment 4 - USD - bank
advance_payment_4 = (
self.env["account.voucher.wizard.purchase"]
- .with_context(context_payment)
+ .with_context(**context_payment)
.create(
{
"journal_id": self.journal_usd_bank.id,
@@ -235,7 +244,7 @@ def test_02_residual_amount_with_bill(self):
# Create Advance Payment 2 - USD - cash
advance_payment_2 = (
self.env["account.voucher.wizard.purchase"]
- .with_context(context_payment)
+ .with_context(**context_payment)
.create(
{
"journal_id": self.journal_usd_cash.id,
@@ -301,7 +310,7 @@ def test_03_residual_amount_big_pre_payment(self):
# Create Advance Payment 2 - USD - cash
advance_payment_2 = (
self.env["account.voucher.wizard.purchase"]
- .with_context(context_payment)
+ .with_context(**context_payment)
.create(
{
"journal_id": self.journal_usd_cash.id,
diff --git a/purchase_advance_payment/views/purchase_view.xml b/purchase_advance_payment/views/purchase_view.xml
index 95d54657920..0bd22ba850e 100644
--- a/purchase_advance_payment/views/purchase_view.xml
+++ b/purchase_advance_payment/views/purchase_view.xml
@@ -24,7 +24,7 @@
/>
-
+
diff --git a/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py b/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py
index 0ef7fdc4fbd..80f62dc8bbb 100644
--- a/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py
+++ b/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py
@@ -2,11 +2,9 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html)
from odoo import _, api, exceptions, fields, models
-from odoo.tools import float_compare
class AccountVoucherWizardPurchase(models.TransientModel):
-
_name = "account.voucher.wizard.purchase"
_description = "Account Voucher Wizard Purchase"
@@ -25,13 +23,17 @@ class AccountVoucherWizardPurchase(models.TransientModel):
compute="_compute_get_journal_currency",
)
currency_id = fields.Many2one("res.currency", "Currency", readonly=True)
- amount_total = fields.Monetary("Amount total", readonly=True)
+ amount_total = fields.Monetary(readonly=True)
amount_advance = fields.Monetary(
"Amount advanced", required=True, currency_field="journal_currency_id"
)
- date = fields.Date("Date", required=True, default=fields.Date.context_today)
+ date = fields.Date(required=True, default=fields.Date.context_today)
currency_amount = fields.Monetary(
- "Curr. amount", readonly=True, currency_field="currency_id"
+ "Curr. amount",
+ readonly=True,
+ currency_field="currency_id",
+ compute="_compute_currency_amount",
+ store=True,
)
payment_ref = fields.Char("Ref.")
@@ -44,15 +46,12 @@ def _compute_get_journal_currency(self):
@api.constrains("amount_advance")
def check_amount(self):
- if self.amount_advance <= 0:
+ if self.journal_currency_id.compare_amounts(self.amount_advance, 0.0) <= 0:
raise exceptions.ValidationError(_("Amount of advance must be positive."))
if self.env.context.get("active_id", False):
- self.onchange_date()
if (
- float_compare(
- self.currency_amount,
- self.order_id.amount_residual,
- precision_digits=2,
+ self.currency_id.compare_amounts(
+ self.currency_amount, self.order_id.amount_residual
)
> 0
):
@@ -79,8 +78,8 @@ def default_get(self, fields_list):
return res
- @api.onchange("journal_id", "date", "amount_advance")
- def onchange_date(self):
+ @api.depends("journal_id", "date", "amount_advance")
+ def _compute_currency_amount(self):
if self.journal_currency_id != self.currency_id:
amount_advance = self.journal_currency_id._convert(
self.amount_advance,
From 8542e0764fdc3cc151b58786e82ceb0c71a3d75e Mon Sep 17 00:00:00 2001
From: sonhd91
Date: Thu, 5 Jan 2023 13:43:01 +0700
Subject: [PATCH 08/12] [16.0][MIG] purchase_advance_payment: Migrate to
version 16.0
---
purchase_advance_payment/README.rst | 18 ++-
purchase_advance_payment/__manifest__.py | 2 +-
purchase_advance_payment/i18n/fr.po | 18 +--
.../i18n/purchase_advance_payment.pot | 4 +-
.../models/purchase_order.py | 2 +-
.../readme/CONTRIBUTORS.rst | 3 +
purchase_advance_payment/readme/CREDITS.rst | 1 +
.../static/description/index.html | 28 +++-
.../tests/test_purchase_advance_payment.py | 143 +++++++++++++++---
.../views/purchase_view.xml | 2 +-
10 files changed, 169 insertions(+), 52 deletions(-)
create mode 100644 purchase_advance_payment/readme/CREDITS.rst
diff --git a/purchase_advance_payment/README.rst b/purchase_advance_payment/README.rst
index ebfd928c518..4e589857b37 100644
--- a/purchase_advance_payment/README.rst
+++ b/purchase_advance_payment/README.rst
@@ -14,13 +14,13 @@ Purchase Advance Payment
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
- :target: https://github.com/OCA/purchase-workflow/tree/15.0/purchase_advance_payment
+ :target: https://github.com/OCA/purchase-workflow/tree/16.0/purchase_advance_payment
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
- :target: https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_advance_payment
+ :target: https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_advance_payment
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
- :target: https://runbot.odoo-community.org/runbot/142/15.0
+ :target: https://runbot.odoo-community.org/runbot/142/16.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -52,7 +52,7 @@ 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 `_.
+`feedback `_.
Do not contact contributors directly about support or help with technical issues.
@@ -69,6 +69,14 @@ Contributors
* Mateu Griful
* Lois Rilo
+* `Trobz `_:
+
+ * Son Ho
+
+Other credits
+~~~~~~~~~~~~~
+
+The migration of this module from 15.0 to 16.0 was financially supported by Camptocamp
Maintainers
~~~~~~~~~~~
@@ -83,6 +91,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.
-This module is part of the `OCA/purchase-workflow `_ project on GitHub.
+This module is part of the `OCA/purchase-workflow `_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
diff --git a/purchase_advance_payment/__manifest__.py b/purchase_advance_payment/__manifest__.py
index 6e63bd4177c..0821aa4fb22 100644
--- a/purchase_advance_payment/__manifest__.py
+++ b/purchase_advance_payment/__manifest__.py
@@ -3,7 +3,7 @@
{
"name": "Purchase Advance Payment",
- "version": "15.0.1.0.0",
+ "version": "16.0.1.0.0",
"author": "Forgeflow, Odoo Community Association (OCA)",
"website": "https://github.com/OCA/purchase-workflow",
"category": "Purchase",
diff --git a/purchase_advance_payment/i18n/fr.po b/purchase_advance_payment/i18n/fr.po
index 0392173c55b..837ff265e93 100644
--- a/purchase_advance_payment/i18n/fr.po
+++ b/purchase_advance_payment/i18n/fr.po
@@ -36,6 +36,11 @@ msgstr ""
msgid "Amount Residual"
msgstr ""
+#. module: purchase_advance_payment
+#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__amount_total
+msgid "Amount Total"
+msgstr ""
+
#. module: purchase_advance_payment
#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__amount_advance
msgid "Amount advanced"
@@ -47,22 +52,19 @@ msgid "Amount in Order Currency"
msgstr ""
#. module: purchase_advance_payment
+#. odoo-python
#: code:addons/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py:0
#, python-format
msgid "Amount of advance is greater than residual amount on purchase"
msgstr ""
#. module: purchase_advance_payment
+#. odoo-python
#: code:addons/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py:0
#, python-format
msgid "Amount of advance must be positive."
msgstr ""
-#. module: purchase_advance_payment
-#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__amount_total
-msgid "Amount total"
-msgstr ""
-
#. module: purchase_advance_payment
#: model_terms:ir.ui.view,arch_db:purchase_advance_payment.view_account_voucher_wizard
msgid "Cancel"
@@ -95,16 +97,12 @@ msgid "Date"
msgstr ""
#. module: purchase_advance_payment
-#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_payment__display_name
#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__display_name
-#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order__display_name
msgid "Display Name"
msgstr ""
#. module: purchase_advance_payment
-#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_payment__id
#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase__id
-#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order__id
msgid "ID"
msgstr ""
@@ -119,9 +117,7 @@ msgid "Journal Currency"
msgstr ""
#. module: purchase_advance_payment
-#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_payment____last_update
#: model:ir.model.fields,field_description:purchase_advance_payment.field_account_voucher_wizard_purchase____last_update
-#: model:ir.model.fields,field_description:purchase_advance_payment.field_purchase_order____last_update
msgid "Last Modified on"
msgstr ""
diff --git a/purchase_advance_payment/i18n/purchase_advance_payment.pot b/purchase_advance_payment/i18n/purchase_advance_payment.pot
index 7cd03dd46b3..b8b69c32c05 100644
--- a/purchase_advance_payment/i18n/purchase_advance_payment.pot
+++ b/purchase_advance_payment/i18n/purchase_advance_payment.pot
@@ -4,7 +4,7 @@
#
msgid ""
msgstr ""
-"Project-Id-Version: Odoo Server 15.0\n"
+"Project-Id-Version: Odoo Server 16.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
@@ -51,12 +51,14 @@ msgid "Amount in Order Currency"
msgstr ""
#. module: purchase_advance_payment
+#. odoo-python
#: code:addons/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py:0
#, python-format
msgid "Amount of advance is greater than residual amount on purchase"
msgstr ""
#. module: purchase_advance_payment
+#. odoo-python
#: code:addons/purchase_advance_payment/wizard/purchase_advance_payment_wizard.py:0
#, python-format
msgid "Amount of advance must be positive."
diff --git a/purchase_advance_payment/models/purchase_order.py b/purchase_advance_payment/models/purchase_order.py
index 0f58b465c28..398e0661246 100644
--- a/purchase_advance_payment/models/purchase_order.py
+++ b/purchase_advance_payment/models/purchase_order.py
@@ -57,7 +57,7 @@ class PurchaseOrder(models.Model):
def _compute_purchase_advance_payment(self):
for order in self:
mls = order.account_payment_ids.mapped("move_id.line_ids").filtered(
- lambda x: x.account_id.internal_type == "payable"
+ lambda x: x.account_id.account_type == "liability_payable"
and x.parent_state == "posted"
)
advance_amount = 0.0
diff --git a/purchase_advance_payment/readme/CONTRIBUTORS.rst b/purchase_advance_payment/readme/CONTRIBUTORS.rst
index 087dd29233f..8077f0385e3 100644
--- a/purchase_advance_payment/readme/CONTRIBUTORS.rst
+++ b/purchase_advance_payment/readme/CONTRIBUTORS.rst
@@ -1,2 +1,5 @@
* Mateu Griful
* Lois Rilo
+* `Trobz `_:
+
+ * Son Ho
diff --git a/purchase_advance_payment/readme/CREDITS.rst b/purchase_advance_payment/readme/CREDITS.rst
new file mode 100644
index 00000000000..70bc307ad0b
--- /dev/null
+++ b/purchase_advance_payment/readme/CREDITS.rst
@@ -0,0 +1 @@
+The migration of this module from 15.0 to 16.0 was financially supported by Camptocamp
diff --git a/purchase_advance_payment/static/description/index.html b/purchase_advance_payment/static/description/index.html
index 5c70bf46113..b0f5f98337f 100644
--- a/purchase_advance_payment/static/description/index.html
+++ b/purchase_advance_payment/static/description/index.html
@@ -367,7 +367,7 @@
Purchase Advance Payment
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
-
+
The module allows to add advance payments on purchase orders and Request
for Quotation. The advance payments are allowed even before confirmation
and before starting the billing process.
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.
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.