# -*- coding: utf-8 -*- ############################################################################# # # Cybrosys Technologies Pvt. Ltd. # # Copyright (C) 2024-TODAY Cybrosys Technologies() # Author: Ayana KP() # # You can modify it under the terms of the GNU LESSER # GENERAL PUBLIC LICENSE (LGPL v3), Version 3. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU LESSER GENERAL PUBLIC LICENSE (LGPL v3) for more details. # # You should have received a copy of the GNU LESSER GENERAL PUBLIC LICENSE # (LGPL v3) along with this program. # If not, see . # ############################################################################# from odoo import api, fields, models, _ class PestRequest(models.Model): """ This model represents requests related to pest management within the context of agriculture. It provides a structured way to initiate and manage requests for pest control measures, treatments, and interventions.""" _name = 'pest.request' _inherit = ["mail.thread", 'mail.activity.mixin'] _description = 'Pest Request In Agriculture Management' _rec_name = 'reference' reference = fields.Char(string='Reference', help='Mention the details of ' 'pesticide request', copy=False, readonly=True, tracking=True, default=lambda self: _('New')) request_date = fields.Date(string='Request Date', tracking=True, help='The date the pesticide request was sent.', default=fields.Date.context_today, required=True) farmer_id = fields.Many2one('res.partner', string='Farmer', help='Mention the corresponding farmer that ' 'request send', required=True, tracking=True) crop_id = fields.Many2one('crop.request', string='Crop', help='Mention the corresponding crop the ' 'pesticide needed', required=True, tracking=True) location_id = fields.Many2one('location.detail', help='Location of details crop and farming', tracking=True, string='Location') pest_id = fields.Many2one('pest.detail', string='Pest', help='Mention the pesticide name Required ', required=True, tracking=True) company_id = fields.Many2one( 'res.company', string='Company', required=True, readonly=True, help='The company associated with the current user or ' 'environment.', default=lambda self: self.env.company) currency_id = fields.Many2one('res.currency', string='Currency', help='Currency used by the company', default=lambda self: self.env.user.company_id.currency_id) pest_quantity = fields.Integer(string='Pest Quantity', tracking=True, help='The quantity of pesticide that is' 'required to be purchased', required=True) pest_cost = fields.Float(string='Pest Cost', required=True, help="The unit price of the pesticide", tracking=True, related='pest_id.pest_cost') total_cost = fields.Float(string='Total Cost', tracking=True, store=True, help="The total cost of the pesticide that was " "purchased.", compute='_compute_total_cost') disease = fields.Text(string='Disease', tracking=True, required=True, help="The corresponding disease of crop") note = fields.Text(string='Note', tracking=True, help="Please describe any additional details here if " "there is a need to mention additional data.") state = fields.Selection( [('draft', 'Draft'), ('pending', 'Pending'), ('approve', 'Approved'), ('rejected', 'Rejected')], help=" The status of pesticide request", string='Status', default='draft', tracking=True) def action_draft(self): """ Function for change state of crop request to cancel """ self.state = 'draft' def action_pending(self): """ Function for change state of pest request to pending """ self.state = 'pending' def action_approved(self): """ Function for change state of pest request to approve """ self.state = 'approve' def action_rejected(self): """ Function for change state of pest request to rejected """ self.state = 'rejected' @api.depends('pest_cost', 'pest_quantity') def _compute_total_cost(self): """Function for calculate total cost of pesticide""" for record in self: record.total_cost = record.pest_cost * record.pest_quantity @api.model def create(self, values): """ Function for create new pest request """ if values.get('reference', _('New')) == _('New'): values['reference'] = self.env['ir.sequence'].next_by_code( 'pest.request') or _('New') res = super(PestRequest, self).create(values) return res