Merge branch '6.4' into 060224

This commit is contained in:
Àngel Àlvarez 2023-02-15 11:49:07 +01:00
commit 7608a59b49
9 changed files with 61 additions and 58 deletions

43
plot.py
View File

@ -135,13 +135,13 @@ class Plantation(ModelSQL, ModelView):
return [('id', 'in', query)]
@classmethod
def search_remaining_quanity(cls, name, clause):
def search_remaining_quantity(cls, name, clause):
pool = Pool()
DO = pool.get('agronomics.denomination_of_origin')
PARCEL_DO = pool.get('agronomics.parcel-agronomics.do')
Parcel = pool.get('agronomics.parcel')
Weighing = pool.get('agronomics_weighing-agronomics_parcel')
MaxProductionAllowed = pool.get('agronomics_max_production_allowed')
Weighing = pool.get('agronomics.weighing-agronomics.parcel')
MaxProductionAllowed = pool.get('agronomics.max.production.allowed')
do = DO.__table__()
parcel = Parcel.__table__()
@ -151,27 +151,22 @@ class Plantation(ModelSQL, ModelView):
_, operator, value = clause
Operator = fields.SQL_OPERATORS[operator]
query = weighing.join(parcel, condition=weighing.parcel==parcel.id)
query = query.where(weighing.table != True)
query = query.select(parcel.id, Sum(weighing.netweight).as_('weight'),
group_by=parcel.id)
query2 = max_production.join(parcel,
condition = ((max_production.crop == p.crop) &
(max_production.variety == p.variety)))
query2 = query2.join(parcel_do,
condition=m.denomination_origin == parcel_do.do)
query2 = query2.select((Min(max_production.max_production
)*parcel.surface).as_('max_production'),
group_by=parcel.id)
query3 = query.join(query2, condition=query.parcel==query2.parcel)
query3.select(query2.max_production-query.weight,
having=Operator(query2.max_production-query.weight, value))
return [('id', 'in', query)]
join1 = weighing.join(parcel, type_='RIGHT',
condition=((weighing.parcel==parcel.id) &
(weighing.table != True)))
join2 = join1.join(parcel_do, type_= 'LEFT',
condition=parcel.id==parcel_do.parcel)
join3 = join2.join(max_production, type_='LEFT',
condition=((max_production.crop == parcel.crop) &
(max_production.variety == parcel.variety)))
query2 = join3.select(parcel.plantation,
Sum(max_production.max_production*parcel.surface -
weighing.netweight).as_('remaining_quantity'),
group_by=parcel.plantation)
query = query2.select(query2.plantation)
query.where = Operator(query2.remaining_quantity, value)
return [('id' , 'in', query)]
class Ecological(ModelSQL, ModelView):
"Ecological"
@ -234,7 +229,7 @@ class Parcel(ModelSQL, ModelView):
)*self.surface, 2)
def get_purchased_quantity(self, name):
return sum([w.netweight for w in self.weighings if not w.table])
return sum([(w.netweight or 0) for w in self.weighings if not w.table])
def get_remaining_quantity(self, name):
return (self.max_production or 0) - (self.purchased_quantity or 0)

View File

@ -176,6 +176,7 @@ class QualityTest(metaclass=PoolMeta):
class TestLineMixin(Model):
__slots__ = ()
product = fields.Function(fields.Many2One('product.product', 'Product', select=True),
'get_product', searcher='search_product')

View File

@ -1,6 +0,0 @@
# This file is part agronomics module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
from .test_agronomics import suite
__all__ = ['suite']

View File

@ -1,26 +0,0 @@
# This file is part agronomics module for Tryton.
# The COPYRIGHT file at the top level of this repository contains
# the full copyright notices and license terms.
import unittest
import doctest
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(CompanyTestMixin, ModuleTestCase):
'Test Agronomics module'
module = 'agronomics'
def suite():
suite = test_suite()
suite.addTests(unittest.TestLoader().loadTestsFromTestCase(
AgronomicsTestCase))
suite.addTests(doctest.DocFileSuite('scenario_production_template.rst',
tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
return suite

14
tests/test_module.py Normal file
View File

@ -0,0 +1,14 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
from trytond.modules.company.tests import CompanyTestMixin
from trytond.tests.test_tryton import ModuleTestCase
class AgronomicsTestCase(CompanyTestMixin, ModuleTestCase):
'Test Agronomics module'
module = 'agronomics'
del ModuleTestCase

23
tests/test_scenario.py Normal file
View File

@ -0,0 +1,23 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
import doctest
import glob
import os
from trytond.tests.test_tryton import doctest_checker, doctest_teardown
def load_tests(loader, tests, pattern):
cwd = os.getcwd()
try:
os.chdir(os.path.dirname(__file__))
for scenario in glob.glob('*.rst'):
tests.addTests(doctest.DocFileSuite(
scenario, tearDown=doctest_teardown, encoding='utf-8',
checker=doctest_checker,
optionflags=doctest.REPORT_ONLY_FIRST_FAILURE))
finally:
os.chdir(cwd)
return tests

View File

@ -1,5 +1,5 @@
[tryton]
version=6.0.0
version=6.4.0
depends:
ir
res

View File

@ -398,7 +398,8 @@ class Weighing(Workflow, ModelSQL, ModelView):
cls.analysis(to_analysis)
def get_not_assigned_weight(self, name):
return self.netweight - sum([p.netweight for p in self.parcels])
return (self.netweight or 0) - sum([(p.netweight or 0)
for p in self.parcels])
@classmethod
@ModelView.button

View File

@ -13,6 +13,7 @@ _WINE_DIGITS = 4
class WineMixin(Model):
__slots__ = ()
wine_quality_comment = fields.Function(fields.Text('Wine Quality Comments'),
'get_wine_quality_comment')