From ea9fd1b5b0f28ab57e3beae024732397af0ac4b0 Mon Sep 17 00:00:00 2001 From: oscar alvarez Date: Thu, 21 Jul 2022 10:17:35 -0500 Subject: [PATCH] Fix --- configuration.py | 2 + folio.py | 142 +++++++++--------------------------- operation.py | 10 +++ service.py | 8 +- stock.py | 5 -- view/configuration_form.xml | 4 +- 6 files changed, 52 insertions(+), 119 deletions(-) diff --git a/configuration.py b/configuration.py index a8bdd82..08b14e9 100644 --- a/configuration.py +++ b/configuration.py @@ -63,6 +63,8 @@ class Configuration(ModelSQL, ModelView): quarantine_rooms = fields.Numeric('Quarantine Rooms', digits=(2, 0), help='In days') booking_email_template = fields.Many2One('email.template', 'Booking Template Email') + storage_by_default = fields.Many2One('stock.location', 'Storage By Default', + domain=[('type', '=', 'storage')], required=False) @staticmethod def default_company(): diff --git a/folio.py b/folio.py index 1ca08c8..bc15498 100644 --- a/folio.py +++ b/folio.py @@ -114,7 +114,8 @@ class Folio(ModelSQL, ModelView): invoice_line = fields.Many2One('account.invoice.line', 'Invoice Line') to_invoice = fields.Boolean('To Invoice', states={ 'invisible': Bool(Eval('invoice_line')), - }, depends=['invoice_line'], help='Mark this checkbox if you want to invoice this item') + }, depends=['invoice_line'], + help='Mark this checkbox if you want to invoice this item') invoice = fields.Function(fields.Many2One('account.invoice', 'Invoice', depends=['invoice_line']), 'get_invoice') invoice_state = fields.Function(fields.Selection( @@ -130,8 +131,6 @@ class Folio(ModelSQL, ModelView): room_amount = fields.Function(fields.Numeric('Room Amount', digits=(16, 2), depends=['nights_quantity', 'unit_price'] ), 'on_change_with_room_amount') - # stock_moves = fields.Many2Many('hotel.folio-stock.move', 'folio', - # 'move', 'Stock Moves', states={'readonly': True}) channel = fields.Function(fields.Many2One('hotel.channel', 'Channel'), 'get_channel') num_children = fields.Function(fields.Integer('Num. Children'), @@ -878,111 +877,6 @@ class FolioGuest(ModelSQL, ModelView): cls.manage_party(data) -class OperationMaintenance(Workflow, ModelSQL, ModelView): - 'Operation Maintenance' - __name__ = 'hotel.operation.maintenance' - operation = fields.Many2One('hotel.operation', 'Operation', states=STATES_MNT) - room = fields.Many2One('hotel.room', 'Room', states=STATES_MNT, select=True, - required=True) - kind = fields.Selection([ - ('maintenance', 'Maintenance'), - ], 'Kind', readonly=True, select=True) - start_date = fields.Date('Start Date', states=STATES_MNT, required=True, - select=True) - end_date = fields.Date('End Date', states=STATES_MNT, required=True, - select=True) - description = fields.Text('Description', states=STATES_MNT, select=True) - state = fields.Selection([ - ('draft', 'Draft'), - ('confirmed', 'Confirmed'), - ('finished', 'Finished'), - ('cancelled', 'Canceled'), - ], 'State', readonly=True, select=True) - - @classmethod - def __setup__(cls): - super(OperationMaintenance, cls).__setup__() - cls._transitions |= set(( - ('draft', 'confirmed'), - ('draft', 'cancelled'), - ('confirmed', 'finished'), - ('confirmed', 'cancelled'), - )) - cls._buttons.update({ - 'cancel': { - 'invisible': ~Eval('state').in_(['draft', 'confirmed']), - }, - 'draft': { - 'invisible': Eval('state') != 'confirmed', - }, - 'confirm': { - 'invisible': Eval('state') != 'draft', - }, - 'finish': { - 'invisible': Eval('state') != 'confirmed', - }, - }) - - @staticmethod - def default_kind(): - return 'maintenance' - - @staticmethod - def default_state(): - return 'draft' - - @classmethod - @ModelView.button - @Workflow.transition('draft') - def draft(cls, records): - pass - - @classmethod - @ModelView.button - @Workflow.transition('cancelled') - def cancel(cls, records): - for mant in records: - mant.delete_operation() - - @classmethod - @ModelView.button - @Workflow.transition('confirmed') - def confirm(cls, records): - for mant in records: - pass - - @classmethod - @ModelView.button - @Workflow.transition('finished') - def finish(cls, records): - for mant in records: - pass - - @classmethod - def write(cls, records, values): - Room = Pool().get('hotel.room') - for rec in records: - if values.get('start_date') or values.get('end_date') or values.get('room'): - start_date = values.get('start_date') or rec.start_date - end_date = values.get('end_date') or rec.end_date - room = Room(values.get('room') or rec.room) - # Operation().check_dates(start_date, end_date, room, rec.operation) - # rec.update_operation({ - # 'start_date': start_date, - # 'end_date': end_date, - # 'room': room.id, - # }) - super(OperationMaintenance, cls).write(records, values) - - def check_method(self): - """ - Check the methods. - """ - Operation = Pool().get('hotel.operation') - Operation().check_dates(self.start_date, self.end_date, self.room, - self.operation) - - class FolioCharge(Workflow, ModelSQL, ModelView): 'Folio Charge' __name__ = 'hotel.folio.charge' @@ -1056,6 +950,38 @@ class FolioCharge(Workflow, ModelSQL, ModelView): res = value['base'] + value['amount'] return res + def do_stock_move(self, name=None): + pool = Pool() + Location = pool.get('stock.location') + Move = pool.get('stock.move') + Config = Pool().get('hotel.configuration') + # FIXME add origin + + locs_customer = Location.search([ + ('type', '=', 'customer') + ]) + customer_loc_id = locs_customer[0].id + + config = Config.get_configuration() + if not self.storage and config.storage_by_default: + storage_id = config.storage_by_default.id + else: + storage_id = self.storage.id + + move, = Move.create([{ + 'product': self.product.id, + 'effective_date': self.date_service, + 'quantity': self.quantity, + 'unit_price': self.product.cost_price, + 'uom': self.product.default_uom.id, + 'from_location': storage_id, + 'to_location': customer_loc_id, + 'origin': str(self), + }]) + self.move = move.id + Move.do([move]) + self.save() + def get_taxed_amount(self, name=None): if self.quantity and self.unit_price: return self.quantity * self.unit_price diff --git a/operation.py b/operation.py index 11d5a8f..71ca416 100644 --- a/operation.py +++ b/operation.py @@ -120,3 +120,13 @@ class Maintenance(Workflow, ModelSQL, ModelView): def get_days(self, name): if self.end_date and self.start_date: return (self.end_date - self.start_date).days + + # FIXME + def check_method(self): + """ + Check the methods. + FIXME + """ + Operation = Pool().get('hotel.operation') + Operation().check_dates(self.start_date, self.end_date, self.room, + self.operation) diff --git a/service.py b/service.py index f61e518..2cde0e1 100644 --- a/service.py +++ b/service.py @@ -251,7 +251,7 @@ class ServiceLine(Workflow, ModelSQL, ModelView): # return folio = folios[0] - new_line = { + record = { 'folio': self.folio.id, 'date_service': self.service.service_date, 'order': self.order, @@ -263,9 +263,9 @@ class ServiceLine(Workflow, ModelSQL, ModelView): 'to_invoice': True, 'state': '', } - - line, = FolioCharge.create([new_line]) - self.write([self], {'charge': line.id}) + charge, = FolioCharge.create([record]) + self.write([self], {'charge': charge.id}) + charge.do_stock_move() class ServiceReport(CompanyReport): diff --git a/stock.py b/stock.py index 03eb7bf..f7bbe48 100644 --- a/stock.py +++ b/stock.py @@ -13,8 +13,3 @@ class Move(metaclass=PoolMeta): models = super(Move, cls)._get_origin() models.append('hotel.folio.charge') return models - - # def get_sale(self, name): - # SaleLine = Pool().get('sale.line') - # if isinstance(self.origin, SaleLine): - # return self.origin.sale.id diff --git a/view/configuration_form.xml b/view/configuration_form.xml index a9e6845..24b5e4f 100644 --- a/view/configuration_form.xml +++ b/view/configuration_form.xml @@ -22,8 +22,8 @@ this repository contains the full copyright notices and license terms. -->