odoo-addon-sale-commission-product-criteria 16.0.1.0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (25) hide show
  1. odoo/addons/sale_commission_product_criteria/README.rst +116 -0
  2. odoo/addons/sale_commission_product_criteria/__init__.py +1 -0
  3. odoo/addons/sale_commission_product_criteria/__manifest__.py +22 -0
  4. odoo/addons/sale_commission_product_criteria/demo/sale_agent_demo.xml +69 -0
  5. odoo/addons/sale_commission_product_criteria/i18n/it.po +427 -0
  6. odoo/addons/sale_commission_product_criteria/i18n/sale_commission_product_criteria.pot +396 -0
  7. odoo/addons/sale_commission_product_criteria/models/__init__.py +5 -0
  8. odoo/addons/sale_commission_product_criteria/models/account_move.py +30 -0
  9. odoo/addons/sale_commission_product_criteria/models/commission.py +266 -0
  10. odoo/addons/sale_commission_product_criteria/models/sale.py +55 -0
  11. odoo/addons/sale_commission_product_criteria/models/sale_commission_line_mixin.py +78 -0
  12. odoo/addons/sale_commission_product_criteria/models/settlement.py +7 -0
  13. odoo/addons/sale_commission_product_criteria/readme/CONTRIBUTORS.rst +6 -0
  14. odoo/addons/sale_commission_product_criteria/readme/DESCRIPTION.rst +16 -0
  15. odoo/addons/sale_commission_product_criteria/readme/USAGE.rst +7 -0
  16. odoo/addons/sale_commission_product_criteria/security/ir.model.access.csv +3 -0
  17. odoo/addons/sale_commission_product_criteria/static/description/icon.png +0 -0
  18. odoo/addons/sale_commission_product_criteria/static/description/index.html +451 -0
  19. odoo/addons/sale_commission_product_criteria/tests/__init__.py +1 -0
  20. odoo/addons/sale_commission_product_criteria/tests/test_sale_commission_product_criteria.py +204 -0
  21. odoo/addons/sale_commission_product_criteria/views/views.xml +239 -0
  22. odoo_addon_sale_commission_product_criteria-16.0.1.0.0.2.dist-info/METADATA +135 -0
  23. odoo_addon_sale_commission_product_criteria-16.0.1.0.0.2.dist-info/RECORD +25 -0
  24. odoo_addon_sale_commission_product_criteria-16.0.1.0.0.2.dist-info/WHEEL +5 -0
  25. odoo_addon_sale_commission_product_criteria-16.0.1.0.0.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,451 @@
1
+ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
2
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <meta name="generator" content="Docutils: https://docutils.sourceforge.io/" />
6
+ <title>Sale Commission Product Criteria</title>
7
+ <style type="text/css">
8
+
9
+ /*
10
+ :Author: David Goodger (goodger@python.org)
11
+ :Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
12
+ :Copyright: This stylesheet has been placed in the public domain.
13
+
14
+ Default cascading style sheet for the HTML output of Docutils.
15
+
16
+ See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
17
+ customize this style sheet.
18
+ */
19
+
20
+ /* used to remove borders from tables and images */
21
+ .borderless, table.borderless td, table.borderless th {
22
+ border: 0 }
23
+
24
+ table.borderless td, table.borderless th {
25
+ /* Override padding for "table.docutils td" with "! important".
26
+ The right padding separates the table cells. */
27
+ padding: 0 0.5em 0 0 ! important }
28
+
29
+ .first {
30
+ /* Override more specific margin styles with "! important". */
31
+ margin-top: 0 ! important }
32
+
33
+ .last, .with-subtitle {
34
+ margin-bottom: 0 ! important }
35
+
36
+ .hidden {
37
+ display: none }
38
+
39
+ .subscript {
40
+ vertical-align: sub;
41
+ font-size: smaller }
42
+
43
+ .superscript {
44
+ vertical-align: super;
45
+ font-size: smaller }
46
+
47
+ a.toc-backref {
48
+ text-decoration: none ;
49
+ color: black }
50
+
51
+ blockquote.epigraph {
52
+ margin: 2em 5em ; }
53
+
54
+ dl.docutils dd {
55
+ margin-bottom: 0.5em }
56
+
57
+ object[type="image/svg+xml"], object[type="application/x-shockwave-flash"] {
58
+ overflow: hidden;
59
+ }
60
+
61
+ /* Uncomment (and remove this text!) to get bold-faced definition list terms
62
+ dl.docutils dt {
63
+ font-weight: bold }
64
+ */
65
+
66
+ div.abstract {
67
+ margin: 2em 5em }
68
+
69
+ div.abstract p.topic-title {
70
+ font-weight: bold ;
71
+ text-align: center }
72
+
73
+ div.admonition, div.attention, div.caution, div.danger, div.error,
74
+ div.hint, div.important, div.note, div.tip, div.warning {
75
+ margin: 2em ;
76
+ border: medium outset ;
77
+ padding: 1em }
78
+
79
+ div.admonition p.admonition-title, div.hint p.admonition-title,
80
+ div.important p.admonition-title, div.note p.admonition-title,
81
+ div.tip p.admonition-title {
82
+ font-weight: bold ;
83
+ font-family: sans-serif }
84
+
85
+ div.attention p.admonition-title, div.caution p.admonition-title,
86
+ div.danger p.admonition-title, div.error p.admonition-title,
87
+ div.warning p.admonition-title, .code .error {
88
+ color: red ;
89
+ font-weight: bold ;
90
+ font-family: sans-serif }
91
+
92
+ /* Uncomment (and remove this text!) to get reduced vertical space in
93
+ compound paragraphs.
94
+ div.compound .compound-first, div.compound .compound-middle {
95
+ margin-bottom: 0.5em }
96
+
97
+ div.compound .compound-last, div.compound .compound-middle {
98
+ margin-top: 0.5em }
99
+ */
100
+
101
+ div.dedication {
102
+ margin: 2em 5em ;
103
+ text-align: center ;
104
+ font-style: italic }
105
+
106
+ div.dedication p.topic-title {
107
+ font-weight: bold ;
108
+ font-style: normal }
109
+
110
+ div.figure {
111
+ margin-left: 2em ;
112
+ margin-right: 2em }
113
+
114
+ div.footer, div.header {
115
+ clear: both;
116
+ font-size: smaller }
117
+
118
+ div.line-block {
119
+ display: block ;
120
+ margin-top: 1em ;
121
+ margin-bottom: 1em }
122
+
123
+ div.line-block div.line-block {
124
+ margin-top: 0 ;
125
+ margin-bottom: 0 ;
126
+ margin-left: 1.5em }
127
+
128
+ div.sidebar {
129
+ margin: 0 0 0.5em 1em ;
130
+ border: medium outset ;
131
+ padding: 1em ;
132
+ background-color: #ffffee ;
133
+ width: 40% ;
134
+ float: right ;
135
+ clear: right }
136
+
137
+ div.sidebar p.rubric {
138
+ font-family: sans-serif ;
139
+ font-size: medium }
140
+
141
+ div.system-messages {
142
+ margin: 5em }
143
+
144
+ div.system-messages h1 {
145
+ color: red }
146
+
147
+ div.system-message {
148
+ border: medium outset ;
149
+ padding: 1em }
150
+
151
+ div.system-message p.system-message-title {
152
+ color: red ;
153
+ font-weight: bold }
154
+
155
+ div.topic {
156
+ margin: 2em }
157
+
158
+ h1.section-subtitle, h2.section-subtitle, h3.section-subtitle,
159
+ h4.section-subtitle, h5.section-subtitle, h6.section-subtitle {
160
+ margin-top: 0.4em }
161
+
162
+ h1.title {
163
+ text-align: center }
164
+
165
+ h2.subtitle {
166
+ text-align: center }
167
+
168
+ hr.docutils {
169
+ width: 75% }
170
+
171
+ img.align-left, .figure.align-left, object.align-left, table.align-left {
172
+ clear: left ;
173
+ float: left ;
174
+ margin-right: 1em }
175
+
176
+ img.align-right, .figure.align-right, object.align-right, table.align-right {
177
+ clear: right ;
178
+ float: right ;
179
+ margin-left: 1em }
180
+
181
+ img.align-center, .figure.align-center, object.align-center {
182
+ display: block;
183
+ margin-left: auto;
184
+ margin-right: auto;
185
+ }
186
+
187
+ table.align-center {
188
+ margin-left: auto;
189
+ margin-right: auto;
190
+ }
191
+
192
+ .align-left {
193
+ text-align: left }
194
+
195
+ .align-center {
196
+ clear: both ;
197
+ text-align: center }
198
+
199
+ .align-right {
200
+ text-align: right }
201
+
202
+ /* reset inner alignment in figures */
203
+ div.align-right {
204
+ text-align: inherit }
205
+
206
+ /* div.align-center * { */
207
+ /* text-align: left } */
208
+
209
+ .align-top {
210
+ vertical-align: top }
211
+
212
+ .align-middle {
213
+ vertical-align: middle }
214
+
215
+ .align-bottom {
216
+ vertical-align: bottom }
217
+
218
+ ol.simple, ul.simple {
219
+ margin-bottom: 1em }
220
+
221
+ ol.arabic {
222
+ list-style: decimal }
223
+
224
+ ol.loweralpha {
225
+ list-style: lower-alpha }
226
+
227
+ ol.upperalpha {
228
+ list-style: upper-alpha }
229
+
230
+ ol.lowerroman {
231
+ list-style: lower-roman }
232
+
233
+ ol.upperroman {
234
+ list-style: upper-roman }
235
+
236
+ p.attribution {
237
+ text-align: right ;
238
+ margin-left: 50% }
239
+
240
+ p.caption {
241
+ font-style: italic }
242
+
243
+ p.credits {
244
+ font-style: italic ;
245
+ font-size: smaller }
246
+
247
+ p.label {
248
+ white-space: nowrap }
249
+
250
+ p.rubric {
251
+ font-weight: bold ;
252
+ font-size: larger ;
253
+ color: maroon ;
254
+ text-align: center }
255
+
256
+ p.sidebar-title {
257
+ font-family: sans-serif ;
258
+ font-weight: bold ;
259
+ font-size: larger }
260
+
261
+ p.sidebar-subtitle {
262
+ font-family: sans-serif ;
263
+ font-weight: bold }
264
+
265
+ p.topic-title {
266
+ font-weight: bold }
267
+
268
+ pre.address {
269
+ margin-bottom: 0 ;
270
+ margin-top: 0 ;
271
+ font: inherit }
272
+
273
+ pre.literal-block, pre.doctest-block, pre.math, pre.code {
274
+ margin-left: 2em ;
275
+ margin-right: 2em }
276
+
277
+ pre.code .ln { color: grey; } /* line numbers */
278
+ pre.code, code { background-color: #eeeeee }
279
+ pre.code .comment, code .comment { color: #5C6576 }
280
+ pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
281
+ pre.code .literal.string, code .literal.string { color: #0C5404 }
282
+ pre.code .name.builtin, code .name.builtin { color: #352B84 }
283
+ pre.code .deleted, code .deleted { background-color: #DEB0A1}
284
+ pre.code .inserted, code .inserted { background-color: #A3D289}
285
+
286
+ span.classifier {
287
+ font-family: sans-serif ;
288
+ font-style: oblique }
289
+
290
+ span.classifier-delimiter {
291
+ font-family: sans-serif ;
292
+ font-weight: bold }
293
+
294
+ span.interpreted {
295
+ font-family: sans-serif }
296
+
297
+ span.option {
298
+ white-space: nowrap }
299
+
300
+ span.pre {
301
+ white-space: pre }
302
+
303
+ span.problematic {
304
+ color: red }
305
+
306
+ span.section-subtitle {
307
+ /* font-size relative to parent (h1..h6 element) */
308
+ font-size: 80% }
309
+
310
+ table.citation {
311
+ border-left: solid 1px gray;
312
+ margin-left: 1px }
313
+
314
+ table.docinfo {
315
+ margin: 2em 4em }
316
+
317
+ table.docutils {
318
+ margin-top: 0.5em ;
319
+ margin-bottom: 0.5em }
320
+
321
+ table.footnote {
322
+ border-left: solid 1px black;
323
+ margin-left: 1px }
324
+
325
+ table.docutils td, table.docutils th,
326
+ table.docinfo td, table.docinfo th {
327
+ padding-left: 0.5em ;
328
+ padding-right: 0.5em ;
329
+ vertical-align: top }
330
+
331
+ table.docutils th.field-name, table.docinfo th.docinfo-name {
332
+ font-weight: bold ;
333
+ text-align: left ;
334
+ white-space: nowrap ;
335
+ padding-left: 0 }
336
+
337
+ /* "booktabs" style (no vertical lines) */
338
+ table.docutils.booktabs {
339
+ border: 0px;
340
+ border-top: 2px solid;
341
+ border-bottom: 2px solid;
342
+ border-collapse: collapse;
343
+ }
344
+ table.docutils.booktabs * {
345
+ border: 0px;
346
+ }
347
+ table.docutils.booktabs th {
348
+ border-bottom: thin solid;
349
+ text-align: left;
350
+ }
351
+
352
+ h1 tt.docutils, h2 tt.docutils, h3 tt.docutils,
353
+ h4 tt.docutils, h5 tt.docutils, h6 tt.docutils {
354
+ font-size: 100% }
355
+
356
+ ul.auto-toc {
357
+ list-style-type: none }
358
+
359
+ </style>
360
+ </head>
361
+ <body>
362
+ <div class="document" id="sale-commission-product-criteria">
363
+ <h1 class="title">Sale Commission Product Criteria</h1>
364
+
365
+ <!-- !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
366
+ !! This file is generated by oca-gen-addon-readme !!
367
+ !! changes will be overwritten. !!
368
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
369
+ !! source digest: sha256:679118d6039b7893a5538b753c6809a13130884e390fb913b1a83cb29c0a0dd4
370
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
371
+ <p><a class="reference external image-reference" 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 image-reference" 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 image-reference" href="https://github.com/OCA/commission/tree/16.0/sale_commission_product_criteria"><img alt="OCA/commission" src="https://img.shields.io/badge/github-OCA%2Fcommission-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/commission-16-0/commission-16-0-sale_commission_product_criteria"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/commission&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372
+ <p>This module allows to set in the same Commission Type different commission rates according to the product on SO/invoice line.</p>
373
+ <p>This is made possible since this module adds a new “Product criteria” type to Commission Type and applies commission rates with the same logic of sale pricelist items.</p>
374
+ <p>For example, such a Commission Type can grant:</p>
375
+ <p>10% on a specific Product A,
376
+ 10$ on Product B,
377
+ 4% on products in Category 1 and
378
+ 5$ on all other products.</p>
379
+ <p>In SO/invoice, system will apply different commissions based on variant/product/category or global, applied hierarchically. This means that for the example above, if product A is assigned to Category 1, commission assigned is 10%, as per variant/product/category/global rule application order.</p>
380
+ <p>Furthermore, these commission type items can be accessed and created by a specific menu, to facilitate their management in environments with lots of records.</p>
381
+ <p>The form for commission type item can be extended by future modules with further conditions to decide when to apply a specific item.</p>
382
+ <p><strong>Table of contents</strong></p>
383
+ <div class="contents local topic" id="contents">
384
+ <ul class="simple">
385
+ <li><a class="reference internal" href="#usage" id="toc-entry-1">Usage</a></li>
386
+ <li><a class="reference internal" href="#bug-tracker" id="toc-entry-2">Bug Tracker</a></li>
387
+ <li><a class="reference internal" href="#credits" id="toc-entry-3">Credits</a><ul>
388
+ <li><a class="reference internal" href="#authors" id="toc-entry-4">Authors</a></li>
389
+ <li><a class="reference internal" href="#contributors" id="toc-entry-5">Contributors</a></li>
390
+ <li><a class="reference internal" href="#maintainers" id="toc-entry-6">Maintainers</a></li>
391
+ </ul>
392
+ </li>
393
+ </ul>
394
+ </div>
395
+ <div class="section" id="usage">
396
+ <h1><a class="toc-backref" href="#toc-entry-1">Usage</a></h1>
397
+ <p>To use features of this module, you need to:</p>
398
+ <ol class="arabic simple">
399
+ <li>Go to Commissions &gt; Configuration &gt; Commission Types.</li>
400
+ <li>Create a Commission Type with type = “Product criteria”.</li>
401
+ <li>Create multiple rules based on variant/product/category or global</li>
402
+ <li>These rules will be sorted according to the same logic of sale pricelist.</li>
403
+ <li>Rest flow is according to OCA sale_commission module.</li>
404
+ </ol>
405
+ </div>
406
+ <div class="section" id="bug-tracker">
407
+ <h1><a class="toc-backref" href="#toc-entry-2">Bug Tracker</a></h1>
408
+ <p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/commission/issues">GitHub Issues</a>.
409
+ In case of trouble, please check there if your issue has already been reported.
410
+ If you spotted it first, help us to smash it by providing a detailed and welcomed
411
+ <a class="reference external" href="https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_product_criteria%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
412
+ <p>Do not contact contributors directly about support or help with technical issues.</p>
413
+ </div>
414
+ <div class="section" id="credits">
415
+ <h1><a class="toc-backref" href="#toc-entry-3">Credits</a></h1>
416
+ <div class="section" id="authors">
417
+ <h2><a class="toc-backref" href="#toc-entry-4">Authors</a></h2>
418
+ <ul class="simple">
419
+ <li>Ilyas</li>
420
+ <li>Ooops404</li>
421
+ </ul>
422
+ </div>
423
+ <div class="section" id="contributors">
424
+ <h2><a class="toc-backref" href="#toc-entry-5">Contributors</a></h2>
425
+ <ul class="simple">
426
+ <li><a class="reference external" href="https://www.ooops404.com">Ooops404</a>:<ul>
427
+ <li>Ilyas &lt;<a class="reference external" href="mailto:irazor147&#64;gmail.com">irazor147&#64;gmail.com</a>&gt;</li>
428
+ </ul>
429
+ </li>
430
+ <li><a class="reference external" href="https://aiontech.company/">Aion Tech</a>:<ul>
431
+ <li>Simone Rubino &lt;<a class="reference external" href="mailto:simone.rubino&#64;aion-tech.it">simone.rubino&#64;aion-tech.it</a>&gt;</li>
432
+ </ul>
433
+ </li>
434
+ </ul>
435
+ </div>
436
+ <div class="section" id="maintainers">
437
+ <h2><a class="toc-backref" href="#toc-entry-6">Maintainers</a></h2>
438
+ <p>This module is maintained by the OCA.</p>
439
+ <a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
440
+ <p>OCA, or the Odoo Community Association, is a nonprofit organization whose
441
+ mission is to support the collaborative development of Odoo features and
442
+ promote its widespread use.</p>
443
+ <p>Current <a class="reference external" href="https://odoo-community.org/page/maintainer-role">maintainer</a>:</p>
444
+ <p><a class="reference external image-reference" href="https://github.com/ilyasProgrammer"><img alt="ilyasProgrammer" src="https://github.com/ilyasProgrammer.png?size=40px" /></a></p>
445
+ <p>This module is part of the <a class="reference external" href="https://github.com/OCA/commission/tree/16.0/sale_commission_product_criteria">OCA/commission</a> project on GitHub.</p>
446
+ <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>
447
+ </div>
448
+ </div>
449
+ </div>
450
+ </body>
451
+ </html>
@@ -0,0 +1 @@
1
+ from . import test_sale_commission_product_criteria
@@ -0,0 +1,204 @@
1
+ # © 2023 ooops404
2
+ # Copyright 2023 Simone Rubino - Aion Tech
3
+ # License AGPL-3 - See https://www.gnu.org/licenses/agpl-3.0.html
4
+
5
+
6
+ from odoo.exceptions import ValidationError
7
+ from odoo.tests.common import TransactionCase
8
+
9
+
10
+ class TestSaleCommission(TransactionCase):
11
+ @classmethod
12
+ def setUpClass(cls):
13
+ super().setUpClass()
14
+ cls.commission_model = cls.env["commission"]
15
+ cls.company = cls.env.ref("base.main_company")
16
+ cls.res_partner_model = cls.env["res.partner"]
17
+ cls.partner = cls.env.ref("base.res_partner_12")
18
+ cls.partner2 = cls.env.ref("base.res_partner_10")
19
+ cls.sale_order_model = cls.env["sale.order"]
20
+ cls.advance_inv_model = cls.env["sale.advance.payment.inv"]
21
+ cls.settle_model = cls.env["commission.settlement"]
22
+ cls.make_settle_model = cls.env["commission.make.settle"]
23
+ cls.make_inv_model = cls.env["commission.make.invoice"]
24
+ cls.product_1 = cls.env.ref("product.product_product_1")
25
+ cls.product_4 = cls.env.ref("product.product_product_4")
26
+ cls.product_5 = cls.env.ref("product.product_product_5")
27
+ cls.product_6 = cls.env.ref("product.product_product_6")
28
+ cls.product_1.write({"invoice_policy": "order"})
29
+ cls.product_4.write({"invoice_policy": "order"})
30
+ cls.product_5.write({"invoice_policy": "order"})
31
+ cls.product_6.write({"commission_free": True})
32
+ cls.product_template_4 = cls.env.ref(
33
+ "product.product_product_4_product_template"
34
+ )
35
+ cls.product_template_4.write({"invoice_policy": "order"})
36
+ cls.journal = cls.env["account.journal"].search(
37
+ [("type", "=", "purchase")], limit=1
38
+ )
39
+ cls.rules_commission_id = cls.env.ref(
40
+ "sale_commission_product_criteria.demo_commission_rules"
41
+ )
42
+ cls.com_item_1 = cls.env.ref(
43
+ "sale_commission_product_criteria.demo_commission_rules_item_1"
44
+ )
45
+ cls.com_item_2 = cls.env.ref(
46
+ "sale_commission_product_criteria.demo_commission_rules_item_2"
47
+ )
48
+ cls.com_item_3 = cls.env.ref(
49
+ "sale_commission_product_criteria.demo_commission_rules_item_3"
50
+ )
51
+ cls.com_item_4 = cls.env.ref(
52
+ "sale_commission_product_criteria.demo_commission_rules_item_4"
53
+ )
54
+
55
+ def test_sale_commission_product_criteria_items(self):
56
+ # items names
57
+ self.com_item_1._compute_commission_item_name_value()
58
+ self.com_item_1.currency_id.position = "after"
59
+ self.com_item_1._compute_commission_item_name_value()
60
+ self.assertEqual(self.com_item_1.name, "All Products")
61
+ self.com_item_1.write({"applied_on": "3_global"})
62
+ self.com_item_2._compute_commission_item_name_value()
63
+ self.assertEqual(
64
+ self.com_item_2.name, "Category: All / Saleable / Office Furniture"
65
+ )
66
+ self.com_item_2.write({"applied_on": "2_product_category"})
67
+ self.com_item_3._compute_commission_item_name_value()
68
+ self.assertEqual(self.com_item_3.name, "Product: Customizable Desk")
69
+ self.com_item_3.write({"applied_on": "1_product"})
70
+ self.com_item_4._compute_commission_item_name_value()
71
+ self.assertEqual(
72
+ self.com_item_4.name, "Variant: Customizable Desk (Steel, White)"
73
+ )
74
+ self.com_item_4.write({"applied_on": "0_product_variant"})
75
+
76
+ # 3_global
77
+ so_1 = self._create_sale_order(self.product_1, self.partner)
78
+ so_1.recompute_lines_agents()
79
+ self.assertEqual(so_1.partner_agent_ids.name, "Agent Rules")
80
+ self.assertEqual(so_1.order_line.agent_ids.amount, 10)
81
+ so_1.action_confirm()
82
+ invoice = self._invoice_sale_order(so_1)
83
+ invoice.recompute_lines_agents()
84
+ invoice.action_post()
85
+
86
+ # 2_product_category
87
+ so = self._create_sale_order(self.product_5, self.partner)
88
+ so.recompute_lines_agents()
89
+ self.assertEqual(so.partner_agent_ids.name, "Agent Rules")
90
+ self.assertEqual(so.order_line.agent_ids.amount, 20)
91
+ so.action_confirm()
92
+ invoice = self._invoice_sale_order(so)
93
+ invoice.recompute_lines_agents()
94
+
95
+ # 1_product 5 %
96
+ pp4 = self.product_template_4.product_variant_id
97
+ so = self._create_sale_order(pp4, self.partner)
98
+ so.recompute_lines_agents()
99
+ self.assertEqual(so.partner_agent_ids.name, "Agent Rules")
100
+ self.assertEqual(so.order_line.agent_ids.amount, 50)
101
+ so.action_confirm()
102
+ invoice = self._invoice_sale_order(so)
103
+ invoice.recompute_lines_agents()
104
+
105
+ # 0_product_variant 15 %
106
+ so = self._create_sale_order(self.product_4, self.partner)
107
+ so.recompute_lines_agents()
108
+ self.assertEqual(so.partner_agent_ids.name, "Agent Rules")
109
+ self.assertEqual(so.order_line.agent_ids.amount, 150)
110
+ so.action_confirm()
111
+ invoice = self._invoice_sale_order(so)
112
+ invoice.recompute_lines_agents()
113
+
114
+ # Commission free product
115
+ so = self._create_sale_order(self.product_6, self.partner)
116
+ so.recompute_lines_agents()
117
+
118
+ # Type != product
119
+ so = self._create_sale_order(self.product_4, self.partner2)
120
+ so.recompute_lines_agents()
121
+
122
+ # net amount
123
+ self.rules_commission_id.amount_base_type = "net_amount"
124
+ so = self._create_sale_order(self.product_4, self.partner)
125
+ so.order_line.agent_ids._compute_amount()
126
+
127
+ # archive
128
+ self.rules_commission_id.action_archive()
129
+ self.rules_commission_id.action_unarchive()
130
+
131
+ # copy
132
+ new_rule = self.rules_commission_id.copy()
133
+ self.assertEqual(len(new_rule.item_ids), len(self.rules_commission_id.item_ids))
134
+
135
+ # change commission_type
136
+ self.rules_commission_id.commission_type = "fixed"
137
+ with self.assertRaises(ValidationError):
138
+ self.rules_commission_id.check_type_change_allowed_moves()
139
+ with self.assertRaises(ValidationError):
140
+ self.rules_commission_id.check_type_change_allowed_sale()
141
+
142
+ # no rule found
143
+ self.env.ref(
144
+ "sale_commission_product_criteria.demo_commission_rules_item_1"
145
+ ).unlink()
146
+ so = self._create_sale_order(self.product_1, self.partner)
147
+ so.order_line.agent_ids._compute_amount()
148
+
149
+ # _check_product_consistency
150
+ with self.assertRaises(ValidationError):
151
+ self.com_item_2.categ_id = False
152
+ with self.assertRaises(ValidationError):
153
+ self.com_item_3.product_tmpl_id = False
154
+ with self.assertRaises(ValidationError):
155
+ self.com_item_4.product_id = False
156
+
157
+ # _onchange_product_id
158
+ self.com_item_4.product_id = self.product_1
159
+ self.com_item_4._onchange_product_id()
160
+ self.com_item_4.with_context(
161
+ default_applied_on="1_product"
162
+ )._onchange_product_id()
163
+ self.com_item_4.product_tmpl_id = self.product_template_4
164
+ self.com_item_4._onchange_product_id()
165
+ self.com_item_4.product_tmpl_id = self.product_template_4
166
+ with self.assertRaises(ValidationError):
167
+ self.com_item_4._onchange_product_tmpl_id()
168
+
169
+ def _create_sale_order(self, product, partner):
170
+ return self.sale_order_model.create(
171
+ {
172
+ "partner_id": partner.id,
173
+ "order_line": [
174
+ (
175
+ 0,
176
+ 0,
177
+ {
178
+ "name": product.name,
179
+ "product_id": product.id,
180
+ "product_uom_qty": 1.0,
181
+ "product_uom": product.uom_id.id,
182
+ "price_unit": 1000,
183
+ },
184
+ )
185
+ ],
186
+ }
187
+ )
188
+
189
+ def _invoice_sale_order(self, sale_order, date=None):
190
+ old_invoices = sale_order.invoice_ids
191
+ wizard = self.advance_inv_model.with_context(
192
+ **{
193
+ "active_model": "sale.order",
194
+ "active_ids": [sale_order.id],
195
+ "active_id": sale_order.id,
196
+ }
197
+ ).create(
198
+ {
199
+ "advance_payment_method": "delivered",
200
+ }
201
+ )
202
+ wizard.create_invoices()
203
+ invoice = sale_order.invoice_ids - old_invoices
204
+ return invoice