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 committed Sep 20, 2024
1 parent 3bc2d6e commit 7688e5a
Show file tree
Hide file tree
Showing 28 changed files with 1,267 additions and 0 deletions.
214 changes: 214 additions & 0 deletions sale_order_sign_oca/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
===================
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 file must be max 2-3 paragraphs, and is required.

The goal of this document is to explain quickly the features of this
module: “what” this module does and “what” it is for. ]

Example:

This module extends the functionality of ... to support ... and to allow
users to ...

**Table of contents**

.. contents::
:local:

Use Cases / Context
===================

[ This file is optional but strongly suggested to allow end-users to
evaluate the module's usefulness in their context. ]

BUSINESS NEED: It should explain the “why” of the module:

- what is the business requirement that generated the need to develop
this module
- in which context or use cases this module can be useful (practical
examples are welcome!).

APPROACH: It could also explain the approach to address the mentioned
need.

USEFUL INFORMATION: It can also inform on related modules:

- modules it depends on and their features
- other modules that can work well together with this one
- suggested setups where the module is useful (eg: multicompany,
multi-website)

Installation
============

[ This file must only be present if there are very specific installation
instructions, such as installing non-python dependencies. The audience
is systems administrators. ]

To install this module, you need to:

1. Do this ...

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

[ This file is not always required; it should explain **how to configure
the module before using it**; it is aimed at users with administration
privileges.

Please be detailed on the path to configuration (eg: do you need to
activate developer mode?), describe step by step configurations and the
use of screenshots is strongly recommended.]

To configure this module, you need to:

- Go to *App* > Menu > Menu item
- Activate boolean… > save
- …

Usage
=====

[ This file is required and contains the instructions on **“how”** to
use the module for end-users.

If the module does not have a visible impact on the user interface, just
add the following sentence:

This module does not impact the user interface.

If that’s not the case, please make sure that every usage step is
covered and remember that images speak more than words!]

To use this module, you need to:

- Go to *App* > Menu > Menu item

*insert screenshot!*

- In “Contact” form, add a value to field *xyz* > save

*insert screenshot!*

- The value of *xyz* is now displayed in the list view.

*insert screenshot!*

Known issues / Roadmap
======================

[ Enumerate known caveats and future potential improvements. It is
mostly intended for end-users, and can also help potential new
contributors discovering new features to implement. ]

- ...

Changelog
=========

[ The change log. The goal of this file is to help readers understand
changes between version. The primary audience is end users and
integrators. Purely technical changes such as code refactoring must not
be mentioned here.

This file may contain ONE level of section titles, underlined with the ~
(tilde) character. Other section markers are forbidden and will likely
break the structure of the README.rst or other documents where this
fragment is included. ]

11.0.x.y.z (YYYY-MM-DD)
-----------------------

- [BREAKING] Breaking changes come first.
(`#70 <https://github.com/OCA/repo/issues/70>`__)
- [ADD] New feature. (`#74 <https://github.com/OCA/repo/issues/74>`__)
- [FIX] Correct this. (`#71 <https://github.com/OCA/repo/issues/71>`__)

.. _x.y.z-yyyy-mm-dd-1:

11.0.x.y.z (YYYY-MM-DD)
-----------------------

- ...

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
------------

- Firstname Lastname [email protected] (optional company
website url)
- Second Person [email protected] (optional company website
url)

Other credits
-------------

[ This file is optional and contains additional credits, other than
authors, contributors, and maintainers. ]

The development of this module has been financially supported by:

- Company 1 name
- Company 2 name

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
22 changes: 22 additions & 0 deletions sale_order_sign_oca/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# 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": [
"views/sale_order.xml",
"views/res_config_settings.xml",
"views/sign_oca_request.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
14 changes: 14 additions & 0 deletions sale_order_sign_oca/models/res_company.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# 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",
)
15 changes: 15 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,15 @@
# 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"

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,
)
60 changes: 60 additions & 0 deletions sale_order_sign_oca/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# 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)
for sale_order in res:
if sale_order.partner_id:
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")
res = super().write(vals)
if new_partner_id and new_partner_id != old_partner_id:
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
Loading

0 comments on commit 7688e5a

Please sign in to comment.