|
|
@ -19,7 +19,8 @@ |
|
|
|
# If not, see <http://www.gnu.org/licenses/>. |
|
|
|
# |
|
|
|
############################################################################# |
|
|
|
from odoo import fields, models |
|
|
|
from odoo import fields, models, _ |
|
|
|
from odoo.exceptions import UserError |
|
|
|
|
|
|
|
|
|
|
|
class CropReport(models.TransientModel): |
|
|
@ -36,13 +37,27 @@ class CropReport(models.TransientModel): |
|
|
|
inner join res_partner on pest_request.farmer_id = res_partner.id |
|
|
|
inner join crop_requests on crop_requests.id = pest_request.crop_id |
|
|
|
inner join pest_details on pest_details.id = pest_request.pest_id""" |
|
|
|
|
|
|
|
today = fields.Date.today() |
|
|
|
if self.date_from: |
|
|
|
if self.date_from > today: |
|
|
|
raise UserError( |
|
|
|
_('You could not set the start date or the end date in the future.')) |
|
|
|
if self.date_to: |
|
|
|
if self.date_to > today: |
|
|
|
raise UserError( |
|
|
|
_('You could not set the start date or the end date in the future.')) |
|
|
|
if self.date_from >= self.date_to: |
|
|
|
raise UserError( |
|
|
|
_('The start date must be inferior to the end date.')) |
|
|
|
|
|
|
|
if self.date_from and self.date_to: |
|
|
|
ret = ret + """ where crop_requests.request_date > '""" + str( |
|
|
|
self.date_from) + """' AND crop_requests.request_date < '""" + str( |
|
|
|
ret = ret + """ where crop_requests.request_date >= '""" + str( |
|
|
|
self.date_from) + """' AND crop_requests.request_date <= '"""\ |
|
|
|
+ str( |
|
|
|
self.date_to) + """'""" |
|
|
|
self.env.cr.execute(ret) |
|
|
|
record = self.env.cr.fetchall() |
|
|
|
print(record) |
|
|
|
data = { |
|
|
|
'form': self.read()[0], |
|
|
|
'date_to': self.date_to, |
|
|
|