Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0] [ADD] sale_commission_agent_restrict_product_criteria #459

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions sale_commission_agent_restrict_product_criteria/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
================================================
Sale Commissions Agent Restrict Product Criteria
================================================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:6e881bf405d5ee94eabd1473b81be573c5ca55af8c1eaca4ae728f2237ef418c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |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%2Fcommission-lightgray.png?logo=github
:target: https://github.com/OCA/commission/tree/14.0/sale_commission_agent_restrict_product_criteria
:alt: OCA/commission
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/commission-14-0/commission-14-0-sale_commission_agent_restrict_product_criteria
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/commission&target_branch=14.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|


**Table of contents**

.. contents::
:local:

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/commission/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/commission/issues/new?body=module:%20sale_commission_agent_restrict_product_criteria%0Aversion:%2014.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* PyTech SRL
* Ooops404

Contributors
~~~~~~~~~~~~

* `Ooops404 <https://www.ooops404.com>`
* `PyTech SRL <https://www.pytech.it>`

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/commission <https://github.com/OCA/commission/tree/14.0/sale_commission_agent_restrict_product_criteria>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions sale_commission_agent_restrict_product_criteria/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "Sale Commissions Agent Restrict Product Criteria",
"version": "14.0.1.0.0",
"author": "PyTech SRL, Ooops404, Odoo Community Association (OCA)",
"maintainers": ["pytech-bot"],
"category": "Sales",
"website": "https://github.com/OCA/commission",
"license": "AGPL-3",
"depends": [
"sale_commission_agent_restrict",
"sale_commission_product_criteria_domain",
],
"data": [
"views/sale_order_views.xml",
],
"installable": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order
from . import sale_order_line
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from odoo import api, fields, models


class SaleOrder(models.Model):
_inherit = "sale.order"

product_domain_ids = fields.Many2many("product.product", string="Products Domain")

@api.onchange("partner_id")
def _onchange_partner_id(self):
product_ids = self.env["product.product"]

Check warning on line 11 in sale_commission_agent_restrict_product_criteria/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_agent_restrict_product_criteria/models/sale_order.py#L11

Added line #L11 was not covered by tests
if self.partner_id:
for item in self.partner_id.commission_item_agent_ids:
commission = item.agent_id.commission_id

Check warning on line 14 in sale_commission_agent_restrict_product_criteria/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_agent_restrict_product_criteria/models/sale_order.py#L14

Added line #L14 was not covered by tests
if commission:
product_ids = self._get_products_from_commission(commission, item)
self.product_domain_ids = product_ids or product_ids.search([])

Check warning on line 17 in sale_commission_agent_restrict_product_criteria/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_agent_restrict_product_criteria/models/sale_order.py#L16-L17

Added lines #L16 - L17 were not covered by tests

@api.model
def _get_products_from_commission(self, commission, item):
product_ids = self.env["product.product"]

Check warning on line 21 in sale_commission_agent_restrict_product_criteria/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_agent_restrict_product_criteria/models/sale_order.py#L21

Added line #L21 was not covered by tests
for rule in commission.item_ids.filtered(
lambda x: x.group_id in item.group_ids
):
if rule.applied_on == "3_global":
product_ids = self.env["product.product"].search([])
break

Check warning on line 27 in sale_commission_agent_restrict_product_criteria/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_agent_restrict_product_criteria/models/sale_order.py#L26-L27

Added lines #L26 - L27 were not covered by tests
elif rule.applied_on == "2_product_category":
product_ids |= self.env["product.product"].search(

Check warning on line 29 in sale_commission_agent_restrict_product_criteria/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_agent_restrict_product_criteria/models/sale_order.py#L29

Added line #L29 was not covered by tests
[("product_tmpl_id.categ_id", "=", rule.categ_id.id)]
)
elif rule.applied_on == "1_product":
product_ids |= self.env["product.product"].search(

Check warning on line 33 in sale_commission_agent_restrict_product_criteria/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_agent_restrict_product_criteria/models/sale_order.py#L33

Added line #L33 was not covered by tests
[("product_tmpl_id", "=", rule.product_tmpl_id.id)]
)
elif rule.applied_on == "0_product_variant":
product_ids |= rule.product_id
return product_ids

Check warning on line 38 in sale_commission_agent_restrict_product_criteria/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_commission_agent_restrict_product_criteria/models/sale_order.py#L37-L38

Added lines #L37 - L38 were not covered by tests
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

product_domain_ids = fields.Many2many(related="order_id.product_domain_ids")
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* `Ooops404 <https://www.ooops404.com>`
* `PyTech SRL <https://www.pytech.it>`
Empty file.
Empty file.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading