Skip to content

Commit

Permalink
Merge 3f2217a into 112271c
Browse files Browse the repository at this point in the history
  • Loading branch information
dreispt committed Nov 4, 2019
2 parents 112271c + 3f2217a commit 0952755
Show file tree
Hide file tree
Showing 18 changed files with 408 additions and 0 deletions.
21 changes: 21 additions & 0 deletions product_documentation_set/README.rst
@@ -0,0 +1,21 @@
**This file is going to be generated by oca-gen-addon-readme.**

*Manual changes will be overwritten.*

Please provide content in the ``readme`` directory:

* **DESCRIPTION.rst** (required)
* INSTALL.rst (optional)
* CONFIGURE.rst (optional)
* **USAGE.rst** (optional, highly recommended)
* DEVELOP.rst (optional)
* ROADMAP.rst (optional)
* HISTORY.rst (optional, recommended)
* **CONTRIBUTORS.rst** (optional, highly recommended)
* CREDITS.rst (optional)

Content of this README will also be drawn from the addon manifest,
from keys such as name, authors, maintainers, development_status,
and license.

A good, one sentence summary in the manifest is also highly recommended.
1 change: 1 addition & 0 deletions product_documentation_set/__init__.py
@@ -0,0 +1 @@
from . import models
19 changes: 19 additions & 0 deletions product_documentation_set/__manifest__.py
@@ -0,0 +1,19 @@
# Copyright 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Product Documentation Sets",
"summary": """
Manage Product Documentation""",
"version": "12.0.1.0.0",
"license": "AGPL-3",
"author": "Open Source Integrators,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/product-attribute",
"depends": ["product"],
"data": [
"security/product_documentation_set.xml",
"views/product_documentation_set.xml",
"views/product_template.xml",
"views/product_category.xml",
],
}
3 changes: 3 additions & 0 deletions product_documentation_set/models/__init__.py
@@ -0,0 +1,3 @@
from . import product_documentation_set
from . import product_category
from . import product_template
16 changes: 16 additions & 0 deletions product_documentation_set/models/product_category.py
@@ -0,0 +1,16 @@
# Copyright 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProductCategory(models.Model):

_inherit = "product.category"

doc_set_ids = fields.Many2many(
"product.doc.set",
string="Documentation Sets",
help="Sets of product documentation, to use for several purposes. "
"Specific sets may be defined by country or language.",
)
80 changes: 80 additions & 0 deletions product_documentation_set/models/product_documentation_set.py
@@ -0,0 +1,80 @@
# Copyright 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class ProductDocumentationSet(models.Model):

_name = "product.doc.set"
_description = "Product Documentation Set"

name = fields.Char(required=True)
product_ids = fields.Many2many("product.template")
category_ids = fields.Many2many("product.category")
usage = fields.Selection(
[("internal", "Internal Reference")],
string="Usage",
help="The purpose for this list of documents.",
)
country_ids = fields.Many2many("res.country", string="Countries")
lang = fields.Selection(
lambda self: self.env["res.lang"].get_installed(), string="Language"
)
active = fields.Boolean("Active?", default=True)
attachment_ids = fields.Many2many("ir.attachment", string="Documents")
notes = fields.Html()

@api.model
def get_usage_document_sets(
self, usage, country=None, lang=None, product=None, category=None
):
"""
Find the Document Sets for a single Product Category,
filtering by the particular Usage, Country and Language.
Search will only be performed on the parameters given
(Country and or Lang).
The search is also done following the chain of parent Categories,
until a Document Set is found.
:param usage: Usage selection option (required)
:param country: Country record (optional)
:param lang: Language selection option (optional)
:param product: Product record to search on (optional)
:param category: Product Category record to search on (optional)
:returns: a recordset of Product Documentation Sets
"""
domain = [("usage", "=", usage)]
if country:
country.ensure_one()
domain.append(("country_ids", "in", country.id))
if lang:
domain.append(("lang", "=", lang))

if product:
product.ensure_one()
domain.append(("product_ids", "in", product.id))
if category:
category.ensure_one()
domain.append(("category_ids", "in", category.id))

document_sets = self.search(domain)

if not document_sets:
# Try again for the Product's Category
product_categ = product and product.categ_id
if product_categ:
document_sets = self.get_usage_document_sets(
usage, country, lang, category=product_categ
)
if not document_sets:
# Try again for the Parent Category (recursively
parent_categ = category and category.parent_id
if parent_categ:
document_sets = self.get_usage_document_sets(
usage, country, lang, category=parent_categ
)
return document_sets
21 changes: 21 additions & 0 deletions product_documentation_set/models/product_template.py
@@ -0,0 +1,21 @@
# Copyright 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class ProductTemplate(models.Model):

_inherit = "product.template"

doc_set_ids = fields.Many2many(
"product.doc.set",
string="Documentation Sets",
help="Sets of product documentation, to use for several purposes. "
"Specific sets may be defined by country or language.",
)

def get_usage_document_sets(self, usage, country=None, lang=None):
return self.env["product.doc.set"].get_usage_document_sets(
usage, country, lang, product=self
)
10 changes: 10 additions & 0 deletions product_documentation_set/readme/CONFIGURE.rst
@@ -0,0 +1,10 @@
To configure this module, go to
Sales > Configuration > Sale Orders > Product Documenttion
and create the product Documentation Sets to be used for each countries and languages.

The Countries and Languages field are optional.
If no terms are found for a particular Country and Language combination,
a lookup will be done for Terms with only that cOuntry, and then for only
that Language.

For best results, ensure that Customers have the Country and Language set.
1 change: 1 addition & 0 deletions product_documentation_set/readme/CONTRIBUTORS.rst
@@ -0,0 +1 @@
* Daniel Reis <dreis@opensourceintegrators.com> (https://opensourceintegrators.com)
7 changes: 7 additions & 0 deletions product_documentation_set/readme/DESCRIPTION.rst
@@ -0,0 +1,7 @@
Define Documentation sets for Products.

These can be used, for example, to send to customers
along with Quotations or Sale orders.

Product Documentation Sets can be defined on Products or Product Categories,
by purpose, country and language, and can have several versions.
1 change: 1 addition & 0 deletions product_documentation_set/readme/USAGE.rst
@@ -0,0 +1 @@
In a Product or Product Category, a Documentation Sets field is available.
25 changes: 25 additions & 0 deletions product_documentation_set/security/product_documentation_set.xml
@@ -0,0 +1,25 @@
<!-- Copyright 2019 Open Source Integrators
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo noupdate="1">

<record model="ir.model.access" id="product_documentation_access_user">
<field name="name">product.doc.set User</field>
<field name="model_id" ref="model_product_doc_set"/>
<field name="group_id" ref="base.group_user"/>
<field name="perm_read" eval="1"/>
<field name="perm_create" eval="0"/>
<field name="perm_write" eval="0"/>
<field name="perm_unlink" eval="0"/>
</record>
<record model="ir.model.access" id="product_documentation_access_manager">
<field name="name">product.doc.set Manager</field>
<field name="model_id" ref="model_product_doc_set"/>
<field name="group_id" ref="base.group_system"/>
<field name="perm_read" eval="1"/>
<field name="perm_create" eval="1"/>
<field name="perm_write" eval="1"/>
<field name="perm_unlink" eval="1"/>
</record>

</odoo>
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions product_documentation_set/tests/__init__.py
@@ -0,0 +1 @@
from . import test_product_doc
74 changes: 74 additions & 0 deletions product_documentation_set/tests/test_product_doc.py
@@ -0,0 +1,74 @@
# Copyright 2019 Open Source Integrators
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.tests.common import TransactionCase


def RECS(recset):
return [(6, 0, recset.mapped("id"))]


class TestProductDoc(TransactionCase):
def setUp(self):
"""
category1 ...........> docset1
|_ category2
|_ product1
|_ product2 ....> docset2
"""
super(TestProductDoc, self).setUp()
ref = self.env.ref
self.DocSet = self.env["product.doc.set"]
self.Category = self.env["product.category"]
self.Product = self.env["product.template"]

self.category1 = self.Category.create({"name": "Category1"})
self.category2 = self.Category.create(
{"name": "Category2", "parent_id": self.category1.id}
)

self.product1 = self.Product.create(
{"name": "Product1", "categ_id": self.category2.id}
)
self.product2 = self.Product.create(
{"name": "Product2", "categ_id": self.category2.id}
)

self.docset1 = self.DocSet.create(
{
"name": "DocSet1",
"usage": "internal",
"lang": "en_US",
"country_ids": RECS(ref("base.fr") + ref("base.be")),
"category_ids": RECS(self.category1),
}
)
self.docset2 = self.DocSet.create(
{
"name": "DocSet2",
"usage": "internal",
"lang": "en_US",
"country_ids": RECS(ref("base.fr") + ref("base.be")),
"product_ids": RECS(self.product2),
}
)

def test_docset_from_parent_category(self):
"""Find DocSet from parent category"""
docset = self.product1.get_usage_document_sets(
"internal", country=self.env.ref("base.fr"), lang="en_US"
)
self.assertEqual(docset, self.docset1)

def test_docset_from_product(self):
"""Find DocSet from Product Template"""
docset = self.product2.get_usage_document_sets(
"internal", country=self.env.ref("base.fr"), lang="en_US"
)
self.assertEqual(docset, self.docset2)

def test_docset_no_match(self):
docset = self.product1.get_usage_document_sets(
"internal", self.env.ref("base.fr"), "en_FR"
)
self.assertFalse(docset)
26 changes: 26 additions & 0 deletions product_documentation_set/views/product_category.xml
@@ -0,0 +1,26 @@
<!-- Copyright 2019 Open Source Integrators
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="product_category_form_view">
<field name="name">product.category.form (in product_documentation)</field>
<field name="model">product.category</field>
<field name="inherit_id" ref="product.product_category_form_view"/>
<field name="arch" type="xml">
<sheet position="inside">
<separator string="Documents"/>
<field name="doc_set_ids"
context="{'default_category_ids': [id]}">
<tree>
<field name="name"/>
<field name="usage"/>
<field name="country_ids" widget="many2many_tags"/>
<field name="lang"/>
</tree>
</field>
</sheet>
</field>
</record>

</odoo>
75 changes: 75 additions & 0 deletions product_documentation_set/views/product_documentation_set.xml
@@ -0,0 +1,75 @@
<!-- Copyright 2019 Open Source Integrators
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->

<odoo>

<record model="ir.ui.view" id="product_doc_set_form_view">
<field name="name">product.doc.set.form (in product_documentation_set)</field>
<field name="model">product.doc.set</field>
<field name="arch" type="xml">
<form>
<sheet>
<h1>
<field name="name"/>
</h1>
<group>
<group>
<field name="usage"/>
<field name="product_ids" widget="many2many_tags"/>
<field name="category_ids" widget="many2many_tags"/>
</group>
<group>
<field name="lang"/>
<field name="country_ids" widget="many2many_tags"/>
<field name="active"/>
</group>
</group>
<notebook>
<page name="attachments" string="Documents">
<field name="attachment_ids" mode="kanban"/>
</page>
<page name="notes" string="Notes">
<field name="notes"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record model="ir.ui.view" id="product_doc_set_search_view">
<field name="name">product.doc.set.search (in product_documentation_set)</field>
<field name="model">product.doc.set</field>
<field name="arch" type="xml">
<search>
<field name="usage" />
<field name="product_ids" />
<field name="category_ids" />
<field name="country_ids" />
<field name="lang" />
</search>
</field>
</record>

<record model="ir.ui.view" id="product_doc_set_tree_view">
<field name="name">product.doc.set.tree (in product_documentation_set)</field>
<field name="model">product.doc.set</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="usage"/>
<field name="category_ids" widget="many2many_tags"/>
<field name="product_ids" widget="many2many_tags"/>
<field name="country_ids" widget="many2many_tags"/>
<field name="lang"/>
</tree>
</field>
</record>

<record model="ir.actions.act_window" id="product_doc_set_act_window">
<field name="name">Product Documentation Set</field>
<field name="res_model">product.doc.set</field>
<field name="view_mode">tree,form</field>
</record>

</odoo>

0 comments on commit 0952755

Please sign in to comment.