Skip to content
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
46 changes: 46 additions & 0 deletions multicompany_property_account_payment_term_restriction/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
.. image:: https://img.shields.io/badge/license-LGPL--3-blue.png
:target: https://www.gnu.org/licenses/lgpl
:alt: License: LGPL-3

======================================================
Multicompany Property Account Payment Term Restriction
======================================================

This module is part of a set of modules that allow to set property fields on
a given model for multiple companies simultaneously. Specifically this module:

* Restricts setting Payment Terms on Partners based on the settings. If a Payment Term is only applicable on Sales documents, trying to set this Payment Term as the Vendor Payment Term on a partner, will trigger a Validation Error.

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/133/11.0


Credits
=======

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

* Guillem Casassas <guillem.casassas@forgeflow.com>

Do not contact contributors directly about support or help with technical issues.


Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

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.

To contribute to this module, please visit https://odoo-community.org.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2023 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
{
"name": "Multi Company Account Payment Term Restriction",
"version": "15.0.1.0.0",
"summary": "Payment Term Multi-Company Restrictions",
"author": "ForgeFlow, Odoo Community Association (OCA)",
"website": "https://github.com/ForgeFlow/multicompany-fixes",
"license": "LGPL-3",
"depends": [
"multicompany_property_account",
"account_payment_term_restriction_sale",
"account_payment_term_restriction_purchase",
],
"data": ["views/partner_views.xml"],
"installable": True,
"application": False,
"auto_install": True,
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import partner
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from odoo import api, models


class PartnerProperty(models.TransientModel):
_inherit = "res.partner.property"

@api.model
def _get_payment_term_fields_applicable_on_mapping(self):
apt_model = self.env["account.payment.term"]
return {
"property_payment_term_id": apt_model.get_sale_applicable_on(),
"property_supplier_payment_term_id": apt_model.get_purchase_applicable_on(),
}

def set_property(self, obj, fieldname, value, properties):
if self.env.context.get("skip_payment_term_restriction", False):
return super().set_property(obj, fieldname, value, properties)
pt_fields_dict = self._get_payment_term_fields_applicable_on_mapping()
if fieldname in pt_fields_dict.keys():
payment_term = self.env["account.payment.term"].browse(value)
applicable_on = pt_fields_dict.get(fieldname)
if payment_term.exists():
payment_term.check_not_applicable(applicable_on, record=obj)
super().set_property(obj, fieldname, value, properties)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_multicompany_property_account_payment_term_restriction
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright 2023 ForgeFlow, S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

from odoo.addons.multicompany_property_account.tests import test_multicompany


class TestMulticompanyProperty(test_multicompany.TestMulticompanyProperty):
def test_partner(self):
return super().test_partner()
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="view_partner_property_multicompany_tree" model="ir.ui.view">
<field
name="name"
>res.partner.property.tree - multicompany_property_account_payment_term_restriction</field>
<field name="model">res.partner.property</field>
<field
name="inherit_id"
ref="multicompany_property_account.view_partner_property_multicompany_tree"
/>
<field name="arch" type="xml">
<field name="property_payment_term_id" position="attributes">
<attribute
name="domain"
>[('applicable_on', 'in', ['sale', 'all'])]</attribute>
</field>
<field name="property_supplier_payment_term_id" position="attributes">
<attribute
name="domain"
>[('applicable_on', 'in', ['purchase', 'all'])]</attribute>
</field>
</field>
</record>
<record id="view_partner_property_multicompany_form" model="ir.ui.view">
<field
name="name"
>res.partner.property.form - multicompany_property_account_payment_term_restriction</field>
<field name="model">res.partner.property</field>
<field
name="inherit_id"
ref="multicompany_property_account.view_partner_property_multicompany_form"
/>
<field name="arch" type="xml">
<field name="property_payment_term_id" position="attributes">
<attribute
name="domain"
>[('applicable_on', 'in', ['sale', 'all'])]</attribute>
</field>
<field name="property_supplier_payment_term_id" position="attributes">
<attribute
name="domain"
>[('applicable_on', 'in', ['purchase', 'all'])]</attribute>
</field>
</field>
</record>
</odoo>
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)