Skip to content

Commit

Permalink
[ADD] Addon: sale_order_sign_oca
Browse files Browse the repository at this point in the history
  • Loading branch information
Tiago Amaral authored and Tiago370 committed Oct 4, 2024
1 parent 3bc2d6e commit 360a6cc
Show file tree
Hide file tree
Showing 24 changed files with 1,193 additions and 0 deletions.
127 changes: 127 additions & 0 deletions sale_order_sign_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
===================
Sale Order Sign Oca
===================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8eed166d2b22be5ca399810f57661fccd2fdab9ff6db9c5e3a77882a25bd9d02
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |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%2Fsign-lightgray.png?logo=github
:target: https://github.com/OCA/sign/tree/14.0/sale_order_sign_oca
:alt: OCA/sign
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sign-14-0/sign-14-0-sale_order_sign_oca
: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/sign&target_branch=14.0
:alt: Try me on Runboat

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

This module allows you to generate manual and automatic signature
requests from sale order to customers.

**Table of contents**

.. contents::
:local:

Configuration
=============

#. Go to Sign > Roles and create a role with the following data:

- Partner type: Expression
- Expression: ${object.partner_id.id}

#. Go to Sign > Templates and create a template with the following data:

- Model: Sale Order
- In one of the fields, you must set the previously created role.

#. (Optional) Go to Sales > Configuration > Settings.

- In the Sale Order Sign section, define a template to enable automatic
task sing requests.
- Use the template previously created.

Usage
=====

Creating a Signature Request from a Sale Order:

- Go to Sales > Quotations.
- Open an existing quotation or create a new one (make sure to fill in
the ``partner_id`` field).
- In the sale order form view, click on the action "Sign from
template".
- Sign Requests will have been generated (and sent) linked to the
selected project and task.

Automatic Signature Request creation:

- Define a template in Sale > Configuration > Settings.
- When an customer is assigned to a sale order, a Sign Request will be
created (and sent) automatically.

Viewing Signature Requests:

- Go to Sale > Orders > Quotations.
- Open a sale order with an associated signature request.
- Click on the smart-button Sign Requests.
- Click on any signature request to view its details, status, and
progress.
- Alternatively, go to Sign > Requests.
- Use the Group By feature to group requests by Project and/or Task.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/sign/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/sign/issues/new?body=module:%20sale_order_sign_oca%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
-------

* KMEE

Contributors
------------

- ``KMEE <https://kmee.com.br/>``\ \_:

- Tiago Amaral [email protected]

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_order_sign_oca/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
23 changes: 23 additions & 0 deletions sale_order_sign_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Sale Order Sign Oca",
"summary": """
KMEE""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "KMEE,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/sign",
"depends": ["sign_oca", "sale"],
"data": [
"security/sale_order_sign_oca_security.xml",
"views/sale_order.xml",
"views/sign_oca_request.xml",
"views/res_config_settings.xml",
],
"demo": [
"demo/sign_oca_role.xml",
"demo/sign_oca_template.xml",
],
}
12 changes: 12 additions & 0 deletions sale_order_sign_oca/demo/sign_oca_role.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record id="sign_role_sale_order_customer" model="sign.oca.role">
<field name="name">Sale Order Customer</field>
<field name="partner_type">expression</field>
<field name="expression_partner">${object.partner_id.id}</field>
</record>

</odoo>
25 changes: 25 additions & 0 deletions sale_order_sign_oca/demo/sign_oca_template.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 KMEE
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo noupdate="1">

<record id="sign_oca_template_sale_order_demo" model="sign.oca.template">
<field name="name">Sale Order Approval</field>
<field name="model_id" ref="sale.model_sale_order" />
<field name="data" type="base64" file="sign_oca/tests/empty.pdf" />
</record>
<record id="sign_oca_template_sale_order_demo_item" model="sign.oca.template.item">
<field
name="template_id"
ref="sale_order_sign_oca.sign_oca_template_sale_order_demo"
/>
<field name="field_id" ref="sign_oca.sign_field_signature" />
<field name="role_id" ref="sale_order_sign_oca.sign_role_sale_order_customer" />
<field name="page">1</field>
<field name="position_x">10</field>
<field name="position_y">10</field>
<field name="width">30</field>
<field name="height">4</field>
<field name="required" eval="True" />
</record>
</odoo>
4 changes: 4 additions & 0 deletions sale_order_sign_oca/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import sale_order
from . import res_company
from . import res_config_settings
from . import sign_oca_request
25 changes: 25 additions & 0 deletions sale_order_sign_oca/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResCompany(models.Model):
_inherit = "res.company"

sale_order_sign_oca_template_id = fields.Many2one(
comodel_name="sign.oca.template",
domain="[('model_id.model', '=', 'sale.order')]",
string="Sale Order Sign Oca Template",
)

sale_order_sign_oca_state = fields.Selection(
[
("draft", "Quotation"),
("sent", "Quotation Sent"),
("sale", "Sale Order"),
("done", "Locked"),
("cancel", "Cancelled"),
],
string="Sales Order Status For Sign Request",
)
40 changes: 40 additions & 0 deletions sale_order_sign_oca/models/res_config_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ResConfigSettings(models.TransientModel):

_inherit = "res.config.settings"

group_sale_order_sign_oca = fields.Boolean(
"Sale Order Sign Template",
implied_group="sale_order_sign_oca.group_sale_order_sign_oca",
)

sale_order_sign_oca_template_id = fields.Many2one(
comodel_name="sign.oca.template",
related="company_id.sale_order_sign_oca_template_id",
string="Sale Order Sign Oca Template",
readonly=False,
)

sale_order_sign_oca_state = fields.Selection(
[
("draft", "Quotation"),
("sent", "Quotation Sent"),
("sale", "Sale Order"),
("done", "Locked"),
("cancel", "Cancelled"),
],
string="Sales Order Status For Sign Request",
default=lambda self: self.env["res.company"]
.browse(self.env.user.company_id.id)
.sale_order_sign_oca_state,
)

def set_values(self):
super(ResConfigSettings, self).set_values()
company = self.env["res.company"].browse(self.env.user.company_id.id)
company.sale_order_sign_oca_state = self.sale_order_sign_oca_state
82 changes: 82 additions & 0 deletions sale_order_sign_oca/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class SaleOrder(models.Model):

_inherit = "sale.order"

sign_request_ids = fields.One2many(
comodel_name="sign.oca.request",
inverse_name="sale_order_id",
string="Sign Requests",
)
sign_request_count = fields.Integer(
string="Sign request count",
compute="_compute_sign_request_count",
compute_sudo=True,
)

@api.depends("sign_request_ids")
def _compute_sign_request_count(self):
for sale_order in self:
sale_order.sign_request_count = len(sale_order.sign_request_ids)

def action_view_sign_requests(self):
self.ensure_one()
result = self.env["ir.actions.act_window"]._for_xml_id(

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

View check run for this annotation

Codecov / codecov/patch

sale_order_sign_oca/models/sale_order.py#L28-L29

Added lines #L28 - L29 were not covered by tests
"sign_oca.sign_oca_request_act_window"
)
result["domain"] = [("id", "in", self.sign_request_ids.ids)]
return result

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

View check run for this annotation

Codecov / codecov/patch

sale_order_sign_oca/models/sale_order.py#L32-L33

Added lines #L32 - L33 were not covered by tests

def _generate_sign_oca_request(self):
sign_request_obj = self.env["sign.oca.request"].sudo()
for sale_order in self:
sign_template = sale_order.company_id.sale_order_sign_oca_template_id
if sign_template:
sign_template = sign_template.sudo()
request = sign_request_obj.create(
sign_template._prepare_sign_oca_request_vals_from_record(sale_order)
)
request.action_send()

@api.model_create_multi
def create(self, vals_list):
res = super().create(vals_list)
if self.env.user.has_group("sale_order_sign_oca.group_sale_order_sign_oca"):
for sale_order in res:
if (
sale_order.partner_id
and sale_order.company_id.sale_order_sign_oca_template_id
and sale_order.company_id.sale_order_sign_oca_state == "draft"
):
sale_order._generate_sign_oca_request()
return res

def write(self, vals):
old_partner_id = self.partner_id
new_partner_id = vals.get("partner_id")
old_state = self.state
new_state = vals.get("state")
res = super().write(vals)
if self.env.user.has_group("sale_order_sign_oca.group_sale_order_sign_oca"):
if (
new_state
and new_state != old_state
and self.company_id.sale_order_sign_oca_template_id
and self.company_id.sale_order_sign_oca_state == new_state
):
self._generate_sign_oca_request()
return res

Check warning on line 73 in sale_order_sign_oca/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_order_sign_oca/models/sale_order.py#L72-L73

Added lines #L72 - L73 were not covered by tests

if (
new_partner_id
and new_partner_id != old_partner_id
and self.company_id.sale_order_sign_oca_template_id
and self.company_id.sale_order_sign_oca_state == self.state
):
self._generate_sign_oca_request()
return res
23 changes: 23 additions & 0 deletions sale_order_sign_oca/models/sign_oca_request.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright 2024 KMEE
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class SignOcaRequest(models.Model):
_inherit = "sign.oca.request"

sale_order_id = fields.Many2one(
comodel_name="sale.order",
string="Sale Order",
compute="_compute_sale_order_id",
readonly=True,
store=True,
)

@api.depends("record_ref")
def _compute_sale_order_id(self):
for item in self.filtered(
lambda x: x.record_ref and x.record_ref._name == "sale.order"
):
item.sale_order_id = item.record_ref.id
14 changes: 14 additions & 0 deletions sale_order_sign_oca/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#. Go to Sign > Roles and create a role with the following data:

- Partner type: Expression
- Expression: ${object.partner_id.id}

#. Go to Sign > Templates and create a template with the following data:

- Model: Sale Order
- In one of the fields, you must set the previously created role.

#. (Optional) Go to Sales > Configuration > Settings.

- In the Sale Order Sign section, define a template to enable automatic task sing requests.
- Use the template previously created.
3 changes: 3 additions & 0 deletions sale_order_sign_oca/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `KMEE <https://kmee.com.br/>`_:

* Tiago Amaral <[email protected]>
1 change: 1 addition & 0 deletions sale_order_sign_oca/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This module allows you to generate manual and automatic signature requests from sale order to customers.
Loading

0 comments on commit 360a6cc

Please sign in to comment.