mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[IMP]subscription_oca: readonly company on sale_subscription, template must have same company or none
This commit is contained in:
@@ -7,7 +7,7 @@ Subscription management
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:ef765aa59e854add1d8f551d169722ba58f7dd04b2720acb051ecd8dd72af96e
|
||||
!! source digest: sha256:991d3417863465f9101a0ed4709e4cc97a3a8b8bcc2a0857d29e9918927ff74f
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
|
||||
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
"maintainers": ["ilyasProgrammer", "aleuffre", "renda-dev", "PicchiSeba"],
|
||||
"depends": ["sale_management", "account"],
|
||||
"data": [
|
||||
"security/ir.model.access.csv",
|
||||
"security/ir_rule.xml",
|
||||
"views/product_template_views.xml",
|
||||
"views/sale_subscription_views.xml",
|
||||
"views/sale_subscription_stage_views.xml",
|
||||
@@ -22,7 +24,6 @@
|
||||
"data/ir_cron.xml",
|
||||
"data/sale_subscription_data.xml",
|
||||
"wizard/close_subscription_wizard.xml",
|
||||
"security/ir.model.access.csv",
|
||||
],
|
||||
"installable": True,
|
||||
"application": True,
|
||||
|
||||
@@ -6,7 +6,7 @@ from datetime import date, datetime
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import AccessError
|
||||
from odoo.exceptions import AccessError, ValidationError
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -29,6 +29,7 @@ class SaleSubscription(models.Model):
|
||||
required=True,
|
||||
index=True,
|
||||
default=lambda self: self.env.company,
|
||||
readonly=True,
|
||||
)
|
||||
partner_id = fields.Many2one(
|
||||
comodel_name="res.partner", required=True, string="Partner", index=True
|
||||
@@ -44,6 +45,7 @@ class SaleSubscription(models.Model):
|
||||
comodel_name="sale.subscription.template",
|
||||
required=True,
|
||||
string="Subscription template",
|
||||
check_company=True,
|
||||
)
|
||||
template_invoicing_mode = fields.Selection(
|
||||
related="template_id.invoicing_mode", readonly=True
|
||||
@@ -161,6 +163,15 @@ class SaleSubscription(models.Model):
|
||||
subscription.action_start_subscription()
|
||||
subscription.generate_invoice()
|
||||
|
||||
@api.constrains("template_id")
|
||||
def _check_template_id(self):
|
||||
if self.template_id.company_id not in [False, self.env.company]:
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Cannot link a Template owned by another company to this subscription"
|
||||
)
|
||||
)
|
||||
|
||||
@api.depends("sale_subscription_line_ids")
|
||||
def _compute_total(self):
|
||||
for record in self:
|
||||
|
||||
@@ -43,6 +43,12 @@ class SaleSubscriptionTemplate(models.Model):
|
||||
)
|
||||
code = fields.Char()
|
||||
recurring_rule_count = fields.Integer(default=1, string="Rule count")
|
||||
company_id = fields.Many2one(
|
||||
"res.company",
|
||||
"Company",
|
||||
default=lambda self: self.env.company,
|
||||
domain=lambda self: [("id", "in", self.env.companies.ids)],
|
||||
)
|
||||
invoice_mail_template_id = fields.Many2one(
|
||||
comodel_name="mail.template",
|
||||
string="Invoice Email",
|
||||
|
||||
24
subscription_oca/security/ir_rule.xml
Normal file
24
subscription_oca/security/ir_rule.xml
Normal file
@@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<odoo>
|
||||
<record id="sale_subscription_rule" model="ir.rule">
|
||||
<field name="name">Sale Subscription rule</field>
|
||||
<field name="model_id" ref="model_sale_subscription" />
|
||||
<field
|
||||
name="domain_force"
|
||||
>['|', ('company_id', 'in', company_ids), ('company_id', '=', False)]</field>
|
||||
</record>
|
||||
<record id="sale_subscription_line_rule" model="ir.rule">
|
||||
<field name="name">Sale Subscription Line rule</field>
|
||||
<field name="model_id" ref="model_sale_subscription_line" />
|
||||
<field
|
||||
name="domain_force"
|
||||
>['|', ('company_id', 'in', company_ids), ('company_id', '=', False)]</field>
|
||||
</record>
|
||||
<record id="sale_subscription_template_rule" model="ir.rule">
|
||||
<field name="name">Sale Subscription Template rule</field>
|
||||
<field name="model_id" ref="model_sale_subscription_template" />
|
||||
<field
|
||||
name="domain_force"
|
||||
>['|', ('company_id', 'in', company_ids), ('company_id', '=', False)]</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -1,3 +1,4 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
||||
<head>
|
||||
@@ -366,7 +367,7 @@ ul.auto-toc {
|
||||
!! This file is generated by oca-gen-addon-readme !!
|
||||
!! changes will be overwritten. !!
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
|
||||
!! source digest: sha256:ef765aa59e854add1d8f551d169722ba58f7dd04b2720acb051ecd8dd72af96e
|
||||
!! source digest: sha256:991d3417863465f9101a0ed4709e4cc97a3a8b8bcc2a0857d29e9918927ff74f
|
||||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
|
||||
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/contract/tree/14.0/subscription_oca"><img alt="OCA/contract" src="https://img.shields.io/badge/github-OCA%2Fcontract-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/contract-14-0/contract-14-0-subscription_oca"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/contract&target_branch=14.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
|
||||
<p>This module allows creating subscriptions that generate recurring invoices or orders. It also enables the sale of products that generate subscriptions.</p>
|
||||
|
||||
@@ -6,6 +6,7 @@ import uuid
|
||||
from dateutil.relativedelta import relativedelta
|
||||
|
||||
from odoo import exceptions, fields
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tests import SavepointCase
|
||||
|
||||
|
||||
@@ -756,3 +757,24 @@ class TestSubscriptionOCA(SavepointCase):
|
||||
)
|
||||
test_res.append(group_stage_ids)
|
||||
return test_res
|
||||
|
||||
def test_template_other_company(self):
|
||||
other_company = self.env["res.company"].create(
|
||||
{
|
||||
"name": "Other Company",
|
||||
}
|
||||
)
|
||||
template = self.env["sale.subscription.template"].create(
|
||||
{
|
||||
"name": "Test Template",
|
||||
"company_id": other_company.id,
|
||||
}
|
||||
)
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env["sale.subscription"].create(
|
||||
{
|
||||
"partner_id": self.partner.id,
|
||||
"pricelist_id": self.pricelist1.id,
|
||||
"template_id": template.id,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
</group>
|
||||
<group name="right_group">
|
||||
<field name="code" readonly="0" />
|
||||
<field name="company_id" />
|
||||
</group>
|
||||
</group>
|
||||
</page>
|
||||
@@ -117,10 +118,25 @@
|
||||
<field name="name" />
|
||||
<field name="recurring_interval" />
|
||||
<field name="recurring_rule_type" />
|
||||
<field name="company_id" />
|
||||
<field name="invoicing_mode" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="view_sale_subscription_template_filter" model="ir.ui.view">
|
||||
<field name="name">sale.subscription.template.filter</field>
|
||||
<field name="model">sale.subscription.template</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="name" />
|
||||
<field name="code" />
|
||||
<field name="company_id" />
|
||||
<field name="invoicing_mode" />
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="sale_subscription_template_act_window" model="ir.actions.act_window">
|
||||
<field name="name">Subscription templates</field>
|
||||
<field name="res_model">sale.subscription.template</field>
|
||||
|
||||
@@ -268,6 +268,7 @@
|
||||
<field name="recurring_next_date" optional="show" />
|
||||
<field name="code" optional="show" />
|
||||
<field name="user_id" optional="show" />
|
||||
<field name="company_id" optional="show" />
|
||||
<field name="recurring_total" sum="Total subtotal" optional="show" />
|
||||
<field name="amount_tax" sum="Total Tax" optional="show" />
|
||||
<field name="amount_total" sum="Total" optional="show" />
|
||||
|
||||
Reference in New Issue
Block a user