Skip to content

Commit e33707d

Browse files
[MIG] purchase_deposit: Migration to 16.0
1 parent c667639 commit e33707d

11 files changed

+72
-66
lines changed

purchase_deposit/README.rst

+8-5
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ Purchase Deposit
1414
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1515
:alt: License: AGPL-3
1616
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
17-
:target: https://github.com/OCA/purchase-workflow/tree/15.0/purchase_deposit
17+
:target: https://github.com/OCA/purchase-workflow/tree/16.0/purchase_deposit
1818
:alt: OCA/purchase-workflow
1919
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
20-
:target: https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_deposit
20+
:target: https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_deposit
2121
:alt: Translate me on Weblate
2222
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
23-
:target: https://runbot.odoo-community.org/runbot/142/15.0
23+
:target: https://runbot.odoo-community.org/runbot/142/16.0
2424
:alt: Try me on Runbot
2525

2626
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -51,7 +51,7 @@ Bug Tracker
5151
Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
5252
In case of trouble, please check there if your issue has already been reported.
5353
If you spotted it first, help us smashing it by providing a detailed and welcomed
54-
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_deposit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
54+
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_deposit%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
5555

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

@@ -71,6 +71,9 @@ Contributors
7171
* Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
7272
* Rattapong Chokmasermkul <rattapongc@ecosoft.co.th>
7373
* Joan Mateu <joan.mateu@forgeflow.com>
74+
* `Quartile <https://www.quartile.co>`__:
75+
76+
* Aung Ko Ko Lin
7477

7578
Maintainers
7679
~~~~~~~~~~~
@@ -85,6 +88,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
8588
mission is to support the collaborative development of Odoo features and
8689
promote its widespread use.
8790

88-
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/15.0/purchase_deposit>`_ project on GitHub.
91+
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/16.0/purchase_deposit>`_ project on GitHub.
8992

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

purchase_deposit/__manifest__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
{
66
"name": "Purchase Deposit",
7-
"version": "15.0.1.0.1",
7+
"version": "16.0.1.0.0",
88
"summary": "Option to create deposit from purchase order",
99
"author": "Elico Corp, Ecosoft, Odoo Community Association (OCA)",
1010
"website": "https://github.com/OCA/purchase-workflow",

purchase_deposit/models/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
# Copyright 2019 Ecosoft Co., Ltd., Kitti U. <kittiu@ecosoft.co.th>
33
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
44

5+
from . import res_company
56
from . import res_config_settings
67
from . import purchase

purchase_deposit/models/purchase.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ def copy_data(self, default=None):
1515
(0, 0, line.copy_data()[0])
1616
for line in self.order_line.filtered(lambda l: not l.is_deposit)
1717
]
18-
return super(PurchaseOrder, self).copy_data(default)
18+
return super().copy_data(default)
1919

2020

2121
class PurchaseOrderLine(models.Model):
@@ -28,7 +28,7 @@ class PurchaseOrderLine(models.Model):
2828
)
2929

3030
def _prepare_account_move_line(self, move=False):
31-
res = super(PurchaseOrderLine, self)._prepare_account_move_line(move=move)
31+
res = super()._prepare_account_move_line(move=move)
3232
if self.is_deposit:
3333
res["quantity"] = -1 * self.qty_invoiced
3434
return res
+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Copyright 2023 Quartile Limited
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
4+
from odoo import fields, models
5+
6+
7+
class ResCompany(models.Model):
8+
_inherit = "res.company"
9+
10+
purchase_deposit_product_id = fields.Many2one(
11+
comodel_name="product.product",
12+
string="Purchase Deposit Product",
13+
domain=[("type", "=", "service")],
14+
help="Default product used for payment advances.",
15+
)
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2019 Elico Corp, Dominique K. <dominique.k@elico-corp.com.sg>
22
# Copyright 2019 Ecosoft Co., Ltd., Kitti U. <kittiu@ecosoft.co.th>
3+
# Copyright 2023 Quartile Limited
34
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
45

56
from odoo import fields, models
@@ -8,10 +9,7 @@
89
class ResConfigSettings(models.TransientModel):
910
_inherit = "res.config.settings"
1011

11-
default_purchase_deposit_product_id = fields.Many2one(
12-
comodel_name="product.product",
13-
string="Purchase Deposit Product",
14-
default_model="purchase.advance.payment.inv",
15-
domain=[("type", "=", "service")],
16-
help="Default product used for payment advances.",
12+
purchase_deposit_product_id = fields.Many2one(
13+
related="company_id.purchase_deposit_product_id",
14+
readonly=False,
1715
)

purchase_deposit/readme/CONTRIBUTORS.rst

+3
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,6 @@
22
* Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
33
* Rattapong Chokmasermkul <rattapongc@ecosoft.co.th>
44
* Joan Mateu <joan.mateu@forgeflow.com>
5+
* `Quartile <https://www.quartile.co>`__:
6+
7+
* Aung Ko Ko Lin

purchase_deposit/static/description/index.html

+8-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
44
<head>
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6-
<meta name="generator" content="Docutils 0.15.1: http://docutils.sourceforge.net/" />
6+
<meta name="generator" content="Docutils: http://docutils.sourceforge.net/" />
77
<title>Purchase Deposit</title>
88
<style type="text/css">
99

@@ -367,7 +367,7 @@ <h1 class="title">Purchase Deposit</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
370-
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/15.0/purchase_deposit"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/purchase-workflow-15-0/purchase-workflow-15-0-purchase_deposit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/142/15.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
370+
<p><a class="reference external" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/16.0/purchase_deposit"><img alt="OCA/purchase-workflow" src="https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github" /></a> <a class="reference external" href="https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_deposit"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external" href="https://runbot.odoo-community.org/runbot/142/16.0"><img alt="Try me on Runbot" src="https://img.shields.io/badge/runbot-Try%20me-875A7B.png" /></a></p>
371371
<p>This module allow purchase order to register deposit similar to that in sales order</p>
372372
<p><strong>Table of contents</strong></p>
373373
<div class="contents local topic" id="contents">
@@ -399,7 +399,7 @@ <h1><a class="toc-backref" href="#id2">Bug Tracker</a></h1>
399399
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/purchase-workflow/issues">GitHub Issues</a>.
400400
In case of trouble, please check there if your issue has already been reported.
401401
If you spotted it first, help us smashing it by providing a detailed and welcomed
402-
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_deposit%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
402+
<a class="reference external" href="https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_deposit%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
403403
<p>Do not contact contributors directly about support or help with technical issues.</p>
404404
</div>
405405
<div class="section" id="credits">
@@ -418,6 +418,10 @@ <h2><a class="toc-backref" href="#id5">Contributors</a></h2>
418418
<li>Kitti Upariphutthiphong &lt;<a class="reference external" href="mailto:kittiu&#64;ecosoft.co.th">kittiu&#64;ecosoft.co.th</a>&gt;</li>
419419
<li>Rattapong Chokmasermkul &lt;<a class="reference external" href="mailto:rattapongc&#64;ecosoft.co.th">rattapongc&#64;ecosoft.co.th</a>&gt;</li>
420420
<li>Joan Mateu &lt;<a class="reference external" href="mailto:joan.mateu&#64;forgeflow.com">joan.mateu&#64;forgeflow.com</a>&gt;</li>
421+
<li><a class="reference external" href="https://www.quartile.co">Quartile</a>:<ul>
422+
<li>Aung Ko Ko Lin</li>
423+
</ul>
424+
</li>
421425
</ul>
422426
</div>
423427
<div class="section" id="maintainers">
@@ -427,7 +431,7 @@ <h2><a class="toc-backref" href="#id6">Maintainers</a></h2>
427431
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
428432
mission is to support the collaborative development of Odoo features and
429433
promote its widespread use.</p>
430-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/15.0/purchase_deposit">OCA/purchase-workflow</a> project on GitHub.</p>
434+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/purchase-workflow/tree/16.0/purchase_deposit">OCA/purchase-workflow</a> project on GitHub.</p>
431435
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
432436
</div>
433437
</div>

purchase_deposit/tests/test_purchase_deposit.py

+17-28
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,23 @@
88

99

1010
class TestPurchaseDeposit(TransactionCase):
11-
def setUp(self):
12-
super(TestPurchaseDeposit, self).setUp()
13-
self.product_model = self.env["product.product"]
14-
self.account_model = self.env["account.account"]
15-
self.invoice_model = self.env["account.move"]
16-
self.default_model = self.env["ir.default"]
11+
@classmethod
12+
def setUpClass(cls):
13+
super().setUpClass()
14+
cls.product_model = cls.env["product.product"]
15+
cls.account_model = cls.env["account.account"]
16+
cls.invoice_model = cls.env["account.move"]
1717

1818
# Create Deposit Account
19-
self.account_deposit = self.account_model.create(
19+
cls.account_deposit = cls.account_model.create(
2020
{
2121
"name": "Purchase Deposit",
2222
"code": "11620",
23-
"user_type_id": self.env.ref(
24-
"account.data_account_type_current_assets"
25-
).id,
23+
"account_type": "asset_current",
2624
}
2725
)
2826
# Create products:
29-
p1 = self.product1 = self.product_model.create(
27+
p1 = cls.product1 = cls.product_model.create(
3028
{
3129
"name": "Test Product 1",
3230
"type": "service",
@@ -35,9 +33,9 @@ def setUp(self):
3533
}
3634
)
3735

38-
self.po = self.env["purchase.order"].create(
36+
cls.po = cls.env["purchase.order"].create(
3937
{
40-
"partner_id": self.ref("base.res_partner_3"),
38+
"partner_id": cls.env.ref("base.res_partner_3").id,
4139
"order_line": [
4240
(
4341
0,
@@ -68,14 +66,12 @@ def test_create_deposit_invoice(self):
6866
self.po.button_confirm()
6967
with Form(CreateDeposit.with_context(**ctx)) as f:
7068
f.advance_payment_method = "percentage"
71-
f.deposit_account_id = self.account_deposit
7269
wizard = f.save()
7370
wizard.amount = 10.0 # 10%
71+
wizard.deposit_account_id = self.account_deposit
7472
wizard.create_invoices()
7573
# New Purchase Deposit is created automatically
76-
deposit_id = self.default_model.sudo().get(
77-
"purchase.advance.payment.inv", "purchase_deposit_product_id"
78-
)
74+
deposit_id = self.env.company.purchase_deposit_product_id.id
7975
deposit = self.product_model.browse(deposit_id)
8076
self.assertEqual(deposit.name, "Purchase Deposit")
8177
# 1 Deposit Invoice is created
@@ -127,20 +123,17 @@ def test_create_deposit_invoice_exception_1(self):
127123
"create_bills": True,
128124
}
129125
CreateDeposit = self.env["purchase.advance.payment.inv"]
130-
# 1. This action is allowed only in Purchase Order sate
131-
with self.assertRaises(UserError):
132-
Form(CreateDeposit.with_context(**ctx)) # Initi wizard
133126
self.po.button_confirm()
134127
self.assertEqual(self.po.state, "purchase")
135-
# 2. The value of the deposit must be positive
128+
# 1. The value of the deposit must be positive
136129
f = Form(CreateDeposit.with_context(**ctx))
137130
f.advance_payment_method = "fixed"
138131
f.amount = 0.0
139132
f.deposit_account_id = self.account_deposit
140133
wizard = f.save()
141134
with self.assertRaises(UserError):
142135
wizard.create_invoices()
143-
# 3. For type percentage, The percentage of the deposit must <= 100
136+
# 2. For type percentage, The percentage of the deposit must <= 100
144137
wizard.advance_payment_method = "percentage"
145138
wizard.amount = 101.0
146139
with self.assertRaises(UserError):
@@ -168,9 +161,7 @@ def test_create_deposit_invoice_exception_2(self):
168161
f.deposit_account_id = self.account_deposit
169162
wizard = f.save()
170163
# 4. Purchase Deposit Product's purchase_method != purchase
171-
deposit_id = self.default_model.sudo().get(
172-
"purchase.advance.payment.inv", "purchase_deposit_product_id"
173-
)
164+
deposit_id = self.env.company.purchase_deposit_product_id.id
174165
deposit = self.product_model.browse(deposit_id)
175166
deposit.purchase_method = "receive"
176167
wizard.purchase_deposit_product_id = deposit
@@ -197,9 +188,7 @@ def test_create_deposit_invoice_exception_3(self):
197188
f.amount = 101.0
198189
f.deposit_account_id = self.account_deposit
199190
wizard = f.save()
200-
deposit_id = self.default_model.sudo().get(
201-
"purchase.advance.payment.inv", "purchase_deposit_product_id"
202-
)
191+
deposit_id = self.env.company.purchase_deposit_product_id.id
203192
deposit = self.product_model.browse(deposit_id)
204193
# 5. Purchase Deposit Product's type != service
205194
deposit.type = "consu"

purchase_deposit/views/res_config_settings_views.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
<div class="o_setting_left_pane" />
1818
<div class="o_setting_right_pane">
1919
<label
20-
for="default_purchase_deposit_product_id"
20+
for="purchase_deposit_product_id"
2121
string="Deposit Payments"
2222
/>
2323
<div class="text-muted">
2424
Product used for deposit payments
2525
</div>
2626
<div class="text-muted">
27-
<field name="default_purchase_deposit_product_id" />
27+
<field name="purchase_deposit_product_id" />
2828
</div>
2929
</div>
3030
</div>

purchase_deposit/wizard/purchase_make_invoice_advance.py

+11-18
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class PurchaseAdvancePaymentInv(models.TransientModel):
2727
comodel_name="product.product",
2828
string="Deposit Payment Product",
2929
domain=[("type", "=", "service")],
30+
default=lambda self: self.env.company.purchase_deposit_product_id,
3031
)
3132
amount = fields.Float(
3233
string="Deposit Payment Amount",
@@ -36,25 +37,23 @@ class PurchaseAdvancePaymentInv(models.TransientModel):
3637
deposit_account_id = fields.Many2one(
3738
comodel_name="account.account",
3839
string="Expense Account",
40+
compute="_compute_deposit_account",
41+
store=True,
42+
readonly=False,
3943
domain=[("deprecated", "=", False)],
4044
help="Account used for deposits",
4145
)
4246
deposit_taxes_id = fields.Many2many(
4347
comodel_name="account.tax",
4448
string="Vendor Taxes",
49+
compute="_compute_deposit_account",
50+
store=True,
51+
readonly=False,
4552
help="Taxes used for deposits",
4653
)
4754

48-
@api.model
49-
def view_init(self, fields):
50-
active_id = self._context.get("active_id")
51-
purchase = self.env["purchase.order"].browse(active_id)
52-
if purchase.state != "purchase":
53-
raise UserError(_("This action is allowed only in Purchase Order sate"))
54-
return super().view_init(fields)
55-
56-
@api.onchange("purchase_deposit_product_id")
57-
def _onchagne_purchase_deposit_product_id(self):
55+
@api.depends("purchase_deposit_product_id")
56+
def _compute_deposit_account(self):
5857
product = self.purchase_deposit_product_id
5958
self.deposit_account_id = product.property_account_expense_id
6059
self.deposit_taxes_id = product.supplier_taxes_id
@@ -120,8 +119,7 @@ def _prepare_deposit_val(self, order, po_line, amount):
120119
"product_id": product.id,
121120
"purchase_line_id": po_line.id,
122121
"tax_ids": [(6, 0, tax_ids)],
123-
"analytic_account_id": po_line.account_analytic_id.id or False,
124-
"analytic_tag_ids": [(6, 0, po_line.analytic_tag_ids.ids)],
122+
"analytic_distribution": po_line.analytic_distribution,
125123
},
126124
)
127125
],
@@ -160,7 +158,6 @@ def _prepare_advance_purchase_line(self, order, product, tax_ids, amount):
160158

161159
def create_invoices(self):
162160
Purchase = self.env["purchase.order"]
163-
IrDefault = self.env["ir.default"].sudo()
164161
purchases = Purchase.browse(self._context.get("active_ids", []))
165162
# Create deposit product if necessary
166163
product = self.purchase_deposit_product_id
@@ -169,11 +166,7 @@ def create_invoices(self):
169166
product = self.purchase_deposit_product_id = self.env[
170167
"product.product"
171168
].create(vals)
172-
IrDefault.set(
173-
"purchase.advance.payment.inv",
174-
"purchase_deposit_product_id",
175-
product.id,
176-
)
169+
self.env.company.purchase_deposit_product_id = product
177170
PurchaseLine = self.env["purchase.order.line"]
178171
for order in purchases:
179172
amount = self.amount

0 commit comments

Comments
 (0)