Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
318 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Copyright 2019 Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
{ | ||
'name': 'Sale General Term', | ||
'summary': "Multi-region and multi-language Sales General Terms", | ||
'version': '12.0.1.0.0', | ||
'license': 'AGPL-3', | ||
'author': 'Open Source Integrators,Odoo Community Association (OCA)', | ||
'website': 'https://github.com/oca/sale-workflow', | ||
'depends': [ | ||
'sale', | ||
], | ||
'data': [ | ||
'views/sale_order.xml', | ||
'security/sale_general_term.xml', | ||
'views/sale_general_term.xml', | ||
'report/sale_report_templates.xml', | ||
], | ||
'demo': [ | ||
'demo/sale_general_term.xml', | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2019 Open Source Integrators | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<odoo noupdate="1"> | ||
|
||
<record model="sale.general.term" id="sale_general_term_demo_uk_us"> | ||
<field name="name">US and UK Terms</field> | ||
<field name="is_enabled" eval="True" /> | ||
<field name="country_ids" eval="[(6, 0 , [ref('base.uk'), ref('base.us')])]" /> | ||
<field name="terms">*** These are the general terms for UK and US ***</field> | ||
</record> | ||
|
||
<record model="sale.general.term" id="sale_general_term_demo_us"> | ||
<field name="name">Specific Terms for US</field> | ||
<field name="is_enabled" eval="True" /> | ||
<field name="country_ids" eval="[(6, 0, [ref('base.us')])]" /> | ||
<field name="lang">en_US</field> | ||
<field name="terms">*** These are the English terms for US ***</field> | ||
</record> | ||
|
||
<record model="sale.general.term" id="sale_general_term_demo_fr_be"> | ||
<field name="name">French Terms</field> | ||
<field name="is_enabled" eval="True" /> | ||
<field name="country_ids" eval="[(6, 0 , [ref('base.fr'), ref('base.be')])]" /> | ||
<field name="terms">*** These are the French terms for France and Belgium ***</field> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from . import sale_general_term | ||
from . import sale_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
# Copyright 2019 Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models, _ | ||
from odoo.exceptions import ValidationError | ||
|
||
|
||
class SaleGeneralTerm(models.Model): | ||
|
||
_name = 'sale.general.term' | ||
_description = 'Sale General Term' | ||
|
||
@api.constrains('is_enabled', 'country_ids') | ||
def _check_is_enabled_country_ids(self): | ||
for term in self: | ||
enabled_terms = self.search([ | ||
('is_enabled', '=', True), | ||
('country_ids', 'in', term.country_ids.ids), | ||
('lang', '=', term.lang) | ||
]) | ||
if len(enabled_terms) > 1: | ||
raise ValidationError(_( | ||
'There are already enabled terms for the Language ' | ||
'and at least one of the Countries selected. ' | ||
'Each Country/Language is allowed only one ' | ||
'enabled General Terms.' | ||
)) | ||
|
||
@api.constrains('is_enabled', 'active') | ||
def _check_is_enabled_active(self): | ||
for term in self: | ||
if term.is_enabled and not term.active: | ||
raise ValidationError(_( | ||
'Enabled terms must be Active' | ||
)) | ||
|
||
name = fields.Char(required=True) | ||
active = fields.Boolean('Active?', default=True) | ||
is_enabled = fields.Boolean('Enabled?') | ||
country_ids = fields.Many2many( | ||
'res.country', | ||
string='Countries') | ||
lang = fields.Selection( | ||
lambda self: self.env['res.lang'].get_installed(), | ||
string='Language') | ||
terms = fields.Html() | ||
|
||
def get_partner_general_terms(self, partner_id): | ||
""" | ||
Find the General Terms to use for a particular Partner. | ||
Looks for the best match based on the Partner's Country and Language. | ||
:param partner:id: a singleton Partner record | ||
:returns: the General Terms record if found, False otherwise | ||
""" | ||
if partner_id: | ||
partner_id.ensure_one() | ||
c1 = [('country_ids', 'in', partner_id.country_id.id)] | ||
c2 = [('lang', '=', partner_id.lang or self.env.user_id.lang)] | ||
for domain in [c1 + c2, c1, c2]: | ||
term = self.search([('is_enabled', '=', True)] + domain) | ||
if term: | ||
term.ensure_one() | ||
return term | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Copyright 2019 Open Source Integrators | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
|
||
_inherit = 'sale.order' | ||
|
||
@api.onchange('partner_id') | ||
def onchange_partner_id_general_terms(self): | ||
Terms = self.env['sale.general.term'] | ||
self.general_term_id = Terms.get_partner_general_terms( | ||
self.partner_id) | ||
|
||
general_term_id = fields.Many2one( | ||
'sale.general.term', | ||
string="General Terms", | ||
domain=[('is_enabled', '=', True)], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
To configure this module, go to | ||
Sales > Configuration > Sale Orders > General Terms | ||
and create the General Term 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* Daniel Reis <dreis@opensourceintegrators.com> (https://opensourceintegrators.com) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Create General Sales Terms texts to automatically append to Sales Orders. | ||
|
||
The General Sales Terms can be defined by countries and languages. | ||
Is is possible to keep several versions in the system, and choose wich | ||
one is currently enabled. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
In a Quotation or Sale Order, when selecting the Customer Partner, | ||
the General Terms field will be set automatically, if an appropriate | ||
terms are found in the configuration. | ||
These terms can also be manually selected by the user. | ||
|
||
The Gerenal Terms will automatically be prnted at the end of the Sale Order report. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<template id="report_saleorder_document_inherit" inherit_id="sale.report_saleorder_document"> | ||
<div name="signature" position="after"> | ||
<div style="display:block; clear:both; page-break-after:always;"> | ||
<div t-if="doc.general_term_id" name="general_term_id"> | ||
<span><t t-raw="doc.general_term_id.terms"/></span> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2019 Open Source Integrators | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<odoo> | ||
|
||
<record model="ir.model.access" id="sale_general_term_access_sale_salesman"> | ||
<field name="name">sale.general.term access Sale Saleman</field> | ||
<field name="model_id" ref="model_sale_general_term"/> | ||
<field name="group_id" ref="sales_team.group_sale_salesman"/> | ||
<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="sale_general_term_access_sale_manager"> | ||
<field name="name">sale.general.term access Sale manager</field> | ||
<field name="model_id" ref="model_sale_general_term"/> | ||
<field name="group_id" ref="sales_team.group_sale_manager"/> | ||
<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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2019 Open Source Integrators | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
|
||
<odoo> | ||
|
||
<record model="ir.ui.view" id="sale_general_term_form_view"> | ||
<field name="name">sale.general.term.form (in sale_general_term)</field> | ||
<field name="model">sale.general.term</field> | ||
<field name="arch" type="xml"> | ||
<form> | ||
<sheet> | ||
<h1> | ||
<field name="name"/> | ||
</h1> | ||
<group> | ||
<group> | ||
<field name="country_ids" widget="many2many_tags"/> | ||
<field name="lang"/> | ||
</group> | ||
<group> | ||
<field name="is_enabled"/> | ||
<field name="active"/> | ||
</group> | ||
</group> | ||
<separator string="General Terms" /> | ||
<field name="terms" /> | ||
</sheet> | ||
</form> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.ui.view" id="sale_general_term_search_view"> | ||
<field name="name">sale.general.term.search (in sale_general_term)</field> | ||
<field name="model">sale.general.term</field> | ||
<field name="arch" type="xml"> | ||
<search> | ||
<field name="country_ids" /> | ||
<field name="lang" /> | ||
<filter name="filter_enabled" | ||
string="Enabled" | ||
domain="[('is_enabled', '=', True)]" /> | ||
</search> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.ui.view" id="sale_general_term_tree_view"> | ||
<field name="name">sale.general.term.tree (in sale_general_term)</field> | ||
<field name="model">sale.general.term</field> | ||
<field name="arch" type="xml"> | ||
<tree decoration-primary="is_enabled" decoration-muted="not active"> | ||
<field name="name"/> | ||
<field name="country_ids" widget="many2many_tags"/> | ||
<field name="lang"/> | ||
<field name="is_enabled"/> | ||
<field name="active" invisible="1"/> | ||
</tree> | ||
</field> | ||
</record> | ||
|
||
<record model="ir.actions.act_window" id="sale_general_term_act_window"> | ||
<field name="name">Sale General Terms</field> | ||
<field name="res_model">sale.general.term</field> | ||
<field name="view_mode">tree,form</field> | ||
<field name="domain">[]</field> | ||
<field name="context">{'default_filter_filter_is_enabled': True}</field> | ||
</record> | ||
|
||
<record model="ir.ui.menu" id="sale_general_term_menu"> | ||
<field name="name">Sale General Terms</field> | ||
<field name="parent_id" ref="sale.menu_sales_config"/> | ||
<field name="action" ref="sale_general_term_act_window"/> | ||
<field name="sequence" eval="16"/> | ||
</record> | ||
|
||
</odoo> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- Copyright 2019 Open Source Integrators | ||
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). --> | ||
<odoo> | ||
|
||
<record model="ir.ui.view" id="sale_order_form_view"> | ||
<field name="name">sale.order.form (in sale_general_term)</field> | ||
<field name="model">sale.order</field> | ||
<field name="inherit_id" ref="sale.view_order_form"/> | ||
<field name="arch" type="xml"> | ||
|
||
<field name="payment_term_id" position="before"> | ||
<field name="general_term_id" required="1" /> | ||
</field> | ||
|
||
</field> | ||
</record> | ||
|
||
</odoo> |