Check rule only if _check_access is set and enforce companies rule

issue4080
This commit is contained in:
Raimon Esteve 2022-03-21 19:13:41 +01:00
parent c08f5c1b4f
commit 0ec0ad0bc4
4 changed files with 46 additions and 15 deletions

View File

@ -153,35 +153,57 @@ class Production(metaclass=PoolMeta):
'readonly': Eval('state').in_(['cancelled', 'done']),
}, depends=['allowed_output_products', 'state'])
allowed_enology_products = fields.Function(fields.One2Many(
'product.product', None, 'Allowed Enology Products', readonly=True),
'product.product', None, 'Allowed Enology Products', readonly=True,
context={
'company': Eval('company'),
},
depends=['company']),
'on_change_with_allowed_enology_products',
setter='set_allowed_products')
allowed_output_products = fields.Function(fields.One2Many(
'product.template', None, 'Allowed Output Products', readonly=True),
'product.template', None, 'Allowed Output Products', readonly=True,
context={
'company': Eval('company'),
},
depends=['company']),
'on_change_with_allowed_output_products',
setter='set_allowed_products')
cost_distributions = fields.One2Many(
'production.cost_price.distribution',
'origin', "Cost Distributions",
domain=[
('template', 'in', Eval('cost_distribution_templates')),
],
states={
'readonly': Eval('state').in_(['cancelled', 'done']),
}, domain=[
('template', 'in', Eval('cost_distribution_templates')),
], depends=['state', 'cost_distribution_template',
'cost_distribution_templates'])
},
context={
'company': Eval('company'),
},
depends=['state', 'cost_distribution_template',
'cost_distribution_templates', 'company'])
cost_distribution_template = fields.Many2One(
'production.cost_price.distribution.template',
"Cost Distribution Template",
domain=[
('id', 'in',
Eval('production_template_cost_distribution_templates'))
], states={
],
states={
'readonly': Eval('state').in_(['cancelled', 'done']),
}, depends=['state',
'production_template_cost_distribution_templates'])
},
context={
'company': Eval('company'),
},
depends=['state',
'production_template_cost_distribution_templates', 'company'])
cost_distribution_templates = fields.Function(
fields.Many2Many('product.template',
None, None, "Cost Product Templates"),
None, None, "Cost Product Templates",
context={
'company': Eval('company'),
},
depends=['company']),
'on_change_with_cost_distribution_templates')
pass_quality = fields.Boolean('Pass Quality')
pass_certification = fields.Boolean('Pass Certification')
@ -487,7 +509,7 @@ class Production(metaclass=PoolMeta):
if output.product not in products:
continue
has_product = True
cost = (production_cost * (1 + cdist.percentatge) -
cost = (production_cost * (1 + cdist.percentatge) -
production_cost)
output_cost += round_price(cost / Decimal(total_output))

View File

@ -71,7 +71,11 @@ class QualitySample(ModelSQL, ModelView):
code = fields.Char('Code', select=True, readonly=True)
reference = fields.Char('Reference')
products = fields.Many2Many('product.product-quality.sample', 'sample',
'product', 'Products')
'product', "Products",
context={
'company': Eval('company'),
},
depends=['company'])
collection_date = fields.DateTime('Collection Date', required=True)
company = fields.Many2One('company.company', 'Company', required=True,
select=True)

View File

@ -13,7 +13,9 @@
</record>
<record model="ir.rule" id="rule_quality_configuration_company1">
<field name="rule_group" ref="rule_group_quality_configuration_company"/>
<field name="domain" eval="[('company', '=', Eval('user', {}).get('company', None))]" pyson="1"/>
<field name="domain"
eval="[('company', 'in', Eval('companies', []))]"
pyson="1"/>
</record>
<record model="ir.sequence.type" id="sequence_type_sample">
@ -94,7 +96,9 @@
</record>
<record model="ir.rule" id="rule_quality_sample1">
<field name="domain" eval="[('company', '=', Eval('user', {}).get('company', None))]" pyson="1"/>
<field name="domain"
eval="[('company', 'in', Eval('companies', []))]"
pyson="1"/>
<field name="rule_group" ref="rule_group_quality_sample"/>
</record>

View File

@ -7,9 +7,10 @@ from trytond.tests.test_tryton import ModuleTestCase
from trytond.tests.test_tryton import suite as test_suite
from trytond.tests.test_tryton import doctest_teardown
from trytond.tests.test_tryton import doctest_checker
from trytond.modules.company.tests import CompanyTestMixin
class AgronomicsTestCase(ModuleTestCase):
class AgronomicsTestCase(CompanyTestMixin, ModuleTestCase):
'Test Agronomics module'
module = 'agronomics'