From afb8abe283a30e014c54016fb257fab5488aec5b Mon Sep 17 00:00:00 2001 From: Oscar Alvarez Date: Mon, 8 Jun 2020 17:39:57 -0500 Subject: [PATCH] Fix service and link to equipment --- __init__.py | 1 - booking.py | 9 +++----- equipment.py | 45 ++++++++++++------------------------ equipment.xml | 45 +++--------------------------------- service.py | 25 ++++++++++++++------ tryton.cfg | 3 ++- view/equipment_view_form.xml | 22 +++++++++++++----- view/equipment_view_tree.xml | 4 +++- view/rental_booking_form.xml | 4 ++-- view/rental_booking_tree.xml | 2 +- view/service_form.xml | 16 +++++++++---- view/service_tree.xml | 1 + 12 files changed, 76 insertions(+), 101 deletions(-) diff --git a/__init__.py b/__init__.py index 6ae17fc..ca5657b 100644 --- a/__init__.py +++ b/__init__.py @@ -32,7 +32,6 @@ def register(): stock.ShipmentOut, stock.ShipmentOutReturn, stock.Move, - equipment.EquipmentModel, equipment.RentalEquipment, module='rental', type_='model') Pool.register( diff --git a/booking.py b/booking.py index 0201786..0a03fe5 100644 --- a/booking.py +++ b/booking.py @@ -21,7 +21,7 @@ class Booking(Workflow, ModelSQL, ModelView): __name__ = 'rental.booking' _rec_name = 'number' number = fields.Char('Number', readonly=True, select=True) - equipment = fields.Many2One('rental.equipment', 'Equipment', states=STATES) + equipment = fields.Many2One('maintenance.equipment', 'Equipment', states=STATES) type_document = fields.Selection([ ('', ''), ('passport', 'Passport'), @@ -48,10 +48,7 @@ class Booking(Workflow, ModelSQL, ModelView): product = fields.Many2One('product.product', 'Product', domain=[ ('template.type', '=', 'assets') ], states=STATES) - category = fields.Many2One('product.category', 'Product Category', - domain=[ - ('leasable', '=', True) - ], states=STATES) + brand = fields.Many2One('maintenance.equipment.brand', 'Brand') lapse_time = fields.Integer('Lapse Time', states=STATES) booking_date = fields.Date('Booking Date', states=STATES) start_date = fields.DateTime('Start Date', states=STATES) @@ -263,7 +260,7 @@ class Booking(Workflow, ModelSQL, ModelView): Party = pool.get('party.party') Rental = pool.get('rental.service') Config = pool.get('rental.configuration') - Equipment = pool.get('rental.equipment') + Equipment = pool.get('maintenance.equipment') Item = pool.get('product.check_list_item') ProductCheckList = pool.get('rental.service.product_check_list') config = Config(1) diff --git a/equipment.py b/equipment.py index c0a1563..bbf86c2 100644 --- a/equipment.py +++ b/equipment.py @@ -1,47 +1,30 @@ # 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.model import ModelView, ModelSQL, fields, Unique -from trytond.pool import Pool +from trytond.model import fields, Unique +from trytond.pool import Pool, PoolMeta -__all__ = [ - 'RentalEquipment', 'EquipmentModel' -] +__all__ = ['RentalEquipment'] -class EquipmentModel(ModelSQL, ModelView): - 'Equipment Model' - __name__ = 'rental.equipment.model' - name = fields.Char('Name', required=True) - - -class RentalEquipment(ModelSQL, ModelView): - 'Rental Equipment' - __name__ = 'rental.equipment' - _rec_name = 'product' - product = fields.Many2One('product.product', 'Product', required=True, - domain=[('template.type', '=', 'assets')]) +class RentalEquipment(metaclass=PoolMeta): + __name__ = 'maintenance.equipment' status = fields.Selection([ - ('available', 'Available'), - ('maintenance', 'Maintenance'), - ('not_available', 'Not Available'), - ], 'Status', readonly=False) + ('available', 'Available'), + ('maintenance', 'Maintenance'), + ('not_available', 'Not Available'), + ('stolen', 'Stolen'), + ], 'Status') issues = fields.Text('issues') - gps_id = fields.Char('GPS Id') gps_passwd = fields.Char('GPS Password') gps_link = fields.Char('GPS Link') - date_return = fields.Function(fields.Date('Date Return'), - 'get_return_date') + date_return = fields.Function(fields.Date('Date Return'), 'get_return_date') current_service = fields.Function(fields.Many2One( 'rental.service', 'Contract Service'), 'get_service') - model = fields.Many2One('rental.equipment.model', 'Model') @classmethod def __setup__(cls): super(RentalEquipment, cls).__setup__() table = cls.__table__() - cls._order = [ - ('product.name', 'ASC'), - ] cls._sql_constraints += [ ('product_uniq', Unique(table, table.product), 'Product already exists!'), @@ -68,8 +51,9 @@ class RentalEquipment(ModelSQL, ModelView): def get_rec_name(self, name): product_name = self.product.name or '' - self._rec_name = product_name - return (self._rec_name) + if self.vin: + product_name = '[' + self.vin + ']' + product_name + return product_name @classmethod def search_rec_name(cls, name, clause): @@ -81,4 +65,5 @@ class RentalEquipment(ModelSQL, ModelView): bool_op, ('product.code',) + tuple(clause[1:]), ('product.name',) + tuple(clause[1:]), + ('vin',) + tuple(clause[1:]), ] diff --git a/equipment.xml b/equipment.xml index 6b8b2ee..79ff073 100644 --- a/equipment.xml +++ b/equipment.xml @@ -4,58 +4,19 @@ this repository contains the full copyright notices and license terms. --> - - - - rental.equipment.model - form - model_view_form - - - rental.equipment.model - tree - model_view_tree - - - Model - rental.equipment.model - - - - - - - - - - - - - - rental.equipment + maintenance.equipment form equipment_view_form - rental.equipment + maintenance.equipment tree equipment_view_tree Equipment - rental.equipment + maintenance.equipment diff --git a/service.py b/service.py index 719dfb9..65f84f4 100644 --- a/service.py +++ b/service.py @@ -36,7 +36,7 @@ class Service(Workflow, ModelSQL, ModelView): ], states={ 'readonly': Eval('state').in_(['done', 'cancelled']), }) - equipment = fields.Many2One('rental.equipment', 'Equipment', states={ + equipment = fields.Many2One('maintenance.equipment', 'Equipment', states={ 'readonly': Eval('state').in_(['done', 'cancelled']), }) service_product = fields.Many2One('product.product', 'Service', @@ -63,7 +63,6 @@ class Service(Workflow, ModelSQL, ModelView): states={ 'readonly': (Eval('state') != 'draft') | Eval('currency', 0), }, depends=['state']) - deposit_paid = fields.Boolean('Deposit Paid', select=True) balance = fields.Function(fields.Numeric('Balance', digits=(16, 2), readonly=True), 'get_balance') comment = fields.Text('Comment', states=STATES) @@ -79,7 +78,6 @@ class Service(Workflow, ModelSQL, ModelView): state = fields.Selection([ ('draft', 'Draft'), ('confirmed', 'Confirmed'), - ('pickup', 'Pick Up'), ('renewed', 'Renewed'), ('done', 'Done'), ('cancelled', 'Cancelled'), @@ -133,11 +131,16 @@ class Service(Workflow, ModelSQL, ModelView): address = fields.Function(fields.Char('Address'), 'get_party_info') email = fields.Function(fields.Char('Email'), 'get_party_info') pickup_user = fields.Many2One('res.user', 'Pickup User') - payment_state = fields.Selection([ + deposit_state = fields.Selection([ ('', ''), - ('pending', 'Pending'), - ('paid', 'Paid'), + ('returned', 'Returned'), + ('partial_paid', 'Partial Paid'), + ('kept', 'Kept'), ], 'Payment State') + deposit_amount = fields.Numeric('Deposit Amount', digits=(16, 2)) + deposit_kept = fields.Numeric('Deposit Kept Amount', digits=(16, 2)) + deposit_balance = fields.Function(fields.Numeric('Deposit Balance', + digits=(16, 2)), 'get_deposit_balance') @classmethod def __setup__(cls): @@ -173,6 +176,9 @@ class Service(Workflow, ModelSQL, ModelView): 'pay_advance': { 'invisible': Eval('state').in_(['done']), }, + 'notification_expiration': { + 'invisible': ~Eval('state').in_(['done', 'draft']), + }, }) cls._error_messages.update({ 'invalid_dates': ('Error in Date Start Service!'), @@ -267,6 +273,7 @@ class Service(Workflow, ModelSQL, ModelView): def renew(cls, records): for rec in records: rec.equipment.write([rec.equipment], {'status': 'not_available'}) + rec.send_rental_emails() @classmethod @ModelView.button @@ -292,7 +299,7 @@ class Service(Workflow, ModelSQL, ModelView): @classmethod @ModelView.button - def expire_notification(cls, records): + def notification_expiration(cls, records): for rec in records: rec.send_expire_emails() @@ -435,6 +442,10 @@ class Service(Workflow, ModelSQL, ModelView): amount_to_pay += config[0].value_early_return return amount_to_pay + def get_deposit_balance(self, name): + if self.deposit_amount and self.deposit_kept: + return (self.deposit_amount - self.deposit_kept) + def get_days_expiration(self, name): if self.end_date: days = (self.end_date - date.today()).days diff --git a/tryton.cfg b/tryton.cfg index 4886530..c287b85 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,5 +1,5 @@ [tryton] -version=5.0.2 +version=5.0.3 depends: party company @@ -8,6 +8,7 @@ depends: email sms account_voucher + maintenance xml: rental.xml configuration.xml diff --git a/view/equipment_view_form.xml b/view/equipment_view_form.xml index 59fc94f..bec3aa9 100644 --- a/view/equipment_view_form.xml +++ b/view/equipment_view_form.xml @@ -1,24 +1,34 @@ -
+