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

[ADD] contract_sale_generation_prevent_loop #344

Open
wants to merge 8 commits into
base: 16.0
Choose a base branch
from
Open
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
59 changes: 59 additions & 0 deletions product_contract_sale_generation/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
================================
Product Contract Sale Generation
================================

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

.. |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-coopiteasy%2Faddons-lightgray.png?logo=github
:target: https://github.com/coopiteasy/addons/tree/16.0/product_contract_sale_generation
:alt: coopiteasy/addons

|badge1| |badge2| |badge3|

When using both product_contract and contract_sale_generation, the sale order generated from the contract will create another contract on confirmation :

SO with a is_contract product, when confirmed, creates a contract. This contract contains the same is_contract product. If this contract is set to generate SO, then this contract will generate SOs with the same is_contract module. On confirmation these SOs will create a contract, and so on.

We break this loop by preventing the creation on contracts if the origin of the SO is a contract.

**Table of contents**

.. contents::
:local:

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

Bugs are tracked on `GitHub Issues <https://github.com/coopiteasy/addons/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/coopiteasy/addons/issues/new?body=module:%20product_contract_sale_generation%0Aversion:%2016.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
~~~~~~~

* Coop IT Easy SC

Maintainers
~~~~~~~~~~~

This module is part of the `coopiteasy/addons <https://github.com/coopiteasy/addons/tree/16.0/product_contract_sale_generation>`_ project on GitHub.

You are welcome to contribute.
1 change: 1 addition & 0 deletions product_contract_sale_generation/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions product_contract_sale_generation/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2017 Pesol (<http://pesol.es>)
# Copyright 2017 Angel Moya <[email protected]>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)


{
"name": "Product Contract Sale Generation",
"version": "16.0.1.0.0",
"category": "Contract Management",
"license": "AGPL-3",
"author": "Coop IT Easy SC",
"website": "https://github.com/coopiteasy/addons",
"depends": ["product_contract", "contract_sale_generation"],
"installable": True,
"data": [
"views/sale_order.xml",
],
}
5 changes: 5 additions & 0 deletions product_contract_sale_generation/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import sale_order
from . import sale_order_line
from . import contract
14 changes: 14 additions & 0 deletions product_contract_sale_generation/models/contract.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2018 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class ContractContract(models.Model):
_inherit = "contract.contract"

def _prepare_recurring_sales_values(self, date_ref=False):
res = super()._prepare_recurring_sales_values(date_ref)
if res:
res[0]["created_from_contract"] = True
return res
17 changes: 17 additions & 0 deletions product_contract_sale_generation/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2021 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models


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

created_from_contract = fields.Boolean(default=False, readonly=True)

def action_create_contract(self):
for order in self:
if order.created_from_contract:
return False
else:
return super().action_create_contract()
18 changes: 18 additions & 0 deletions product_contract_sale_generation/models/sale_order_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2021 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import models


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

def _compute_qty_to_invoice(self):
res = super()._compute_qty_to_invoice()
for line in self:
if line.order_id.created_from_contract:
# put back the right quantity to invoice
line.filtered("product_id.is_contract").update(
{"qty_to_invoice": line.product_uom_qty}
)
return res
5 changes: 5 additions & 0 deletions product_contract_sale_generation/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
When using both product_contract and contract_sale_generation, the sale order generated from the contract will create another contract on confirmation :

SO with a is_contract product, when confirmed, creates a contract. This contract contains the same is_contract product. If this contract is set to generate SO, then this contract will generate SOs with the same is_contract module. On confirmation these SOs will create a contract, and so on.

We break this loop by preventing the creation on contracts if the origin of the SO is a contract.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Loading