From 541321b1eb2fa7de5078c271e2cd34268a25792d Mon Sep 17 00:00:00 2001 From: Fabricio Costa Alisedo Date: Thu, 14 Mar 2024 18:33:34 +0100 Subject: [PATCH] Upgraded in Odoo 17.0.24.17 Closes #116 --- __manifest__.py | 2 +- data/channel_marketplace.xml | 16 ++++++++++ models/orders.py | 24 +++++++++++++-- models/shipment.py | 59 ++++++++++++++++++++++++++++++++++-- views/orders_view.xml | 7 +++++ views/shipment_view.xml | 12 ++++++++ 6 files changed, 114 insertions(+), 6 deletions(-) create mode 100644 data/channel_marketplace.xml diff --git a/__manifest__.py b/__manifest__.py index acaba63a..492b54b5 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -9,7 +9,7 @@ { 'name': 'MercadoLibre Publisher / Mercado Libre Odoo Connector', 'summary': 'MercadoLibre Publisher / Mercado Libre Odoo Connector', - 'version': '17.0.24.14', + 'version': '17.0.24.17', 'author': 'Moldeo Interactive', 'website': 'https://www.moldeointeractive.com', "category": "Sales", diff --git a/data/channel_marketplace.xml b/data/channel_marketplace.xml new file mode 100644 index 00000000..abdb2b7d --- /dev/null +++ b/data/channel_marketplace.xml @@ -0,0 +1,16 @@ + + + + + + MercadoLibre + marketplace + + + + MercadoShops + mshops + + + + diff --git a/models/orders.py b/models/orders.py index b2e87997..2e422884 100644 --- a/models/orders.py +++ b/models/orders.py @@ -130,9 +130,17 @@ def _search_meli_buyer_name( self, operator, value ): def _get_meli_order( self ): for so in self: - so.meli_order = so.meli_orders and so.meli_orders[0] - so.meli_buyer = so.meli_order and so.meli_order.buyer - so.meli_buyer_name = so.meli_buyer and so.meli_buyer.name + so.meli_order = False + so.meli_buyer = False + so.meli_buyer_name = False + + meli_order = so.meli_orders and so.meli_orders[0] + if meli_order: + so.meli_order = meli_order + meli_buyer = meli_order and meli_order.buyer + if meli_buyer: + so.meli_buyer = meli_buyer + so.meli_buyer_name = meli_buyer and meli_buyer.name meli_order = fields.Many2one( 'mercadolibre.orders',string="Meli Orden", compute="_get_meli_order" ) meli_buyer = fields.Many2one( "mercadolibre.buyers",string="Meli Comprador", compute="_get_meli_order") @@ -182,6 +190,8 @@ def _get_meli_order( self ): # 'meli_seller': fields.text( string='Seller' ), meli_shipping_id = fields.Char('Meli Shipping Id') meli_shipment = fields.Many2one('mercadolibre.shipment',string='Meli Shipment Obj') + meli_shipment_pdf_file = fields.Binary(string='Pdf File',attachment=True, related="meli_shipment.pdf_file",readonly=True) + meli_shipment_pdf_filename = fields.Char(string='Pdf Filename',related="meli_shipment.pdf_filename",readonly=True) meli_shipment_logistic_type = fields.Char(string="Logistic Type",index=True) meli_update_forbidden = fields.Boolean(string="Bloqueado para actualizar desde ML",default=False, index=True) @@ -505,6 +515,14 @@ def meli_oerp_update( self ): res = order.meli_orders[0].orders_update_order() return res + def meli_oerp_print( self ): + res = {} + for order in self: + if order.meli_shipment: + res = order.meli_shipment.shipment_print( include_ready_to_print=True ) + return res + + _sql_constraints = [ ('unique_meli_order_id', 'unique(meli_order_id)', 'Meli Order id already exists!') ] diff --git a/models/shipment.py b/models/shipment.py index 952ee784..e83cb909 100644 --- a/models/shipment.py +++ b/models/shipment.py @@ -65,14 +65,16 @@ def shipment_print(self, context=None, meli=None, config=None): config = company _logger.info( "shipment_print context: " + str(context) ) - shipment_ids = ('active_ids' in context and context['active_ids']) or [] + active_ids = ('active_ids' in context and context['active_ids']) or [] + shipment_ids = [] #check if model is stock_picking or mercadolibre.shipment #stock.picking > sale_id is the order, then the shipment is sale_id.meli_shipment active_model = context.get("active_model") _logger.info( "shipment_print active_model: " + str(active_model) ) + if active_model == "stock.picking": shipment_ids_from_pick = [] - for spick_id in shipment_ids: + for spick_id in active_ids: spick = self.env["stock.picking"].browse(spick_id) sale_order = spick.sale_id if sale_order and sale_order.meli_shipment: @@ -80,6 +82,15 @@ def shipment_print(self, context=None, meli=None, config=None): shipment_ids = shipment_ids_from_pick _logger.info("stock.picking shipment_ids:"+str(shipment_ids)) + if active_model == "sale.order": + shipment_ids_from_order = [] + for order_id in active_ids: + sale_order = self.env["sale.order"].browse(order_id) + if sale_order and sale_order.meli_shipment: + shipment_ids_from_order.append(sale_order.meli_shipment.id) + shipment_ids = shipment_ids_from_order + _logger.info("sale.order shipment_ids:"+str(shipment_ids)) + shipment_obj = self.env['mercadolibre.shipment'] warningobj = self.env['meli.warning'] @@ -93,6 +104,50 @@ def shipment_print(self, context=None, meli=None, config=None): return self.shipment_print_report(shipment_ids=shipment_ids,meli=meli,config=config,include_ready_to_print=self.include_ready_to_print) + def shipment_sale_order_print( self, context=None, meli=None, config=None): + _logger.info("shipment_sale_order_print") + context = context or self.env.context + company = self.env.user.company_id + if not config: + config = company + order_ids = ('active_ids' in context and context['active_ids']) or [] + #product_obj = self.env['product.template'] + sale_obj = self.env['sale.order'] + shipment_obj = self.env['mercadolibre.shipment'] + warningobj = self.env['meli.warning'] + + if not meli: + meli = self.env['meli.util'].get_new_instance(company) + if meli.need_login(): + return meli.redirect_login() + + sep = "" + shipment_ids= [] + + for order_id in order_ids: + #sacar la orden relacionada + #de la orden sacar el shipping id + sorder = sale_obj.browse(order_id) + shipid = None + shipment = None + if (sorder): + if (sorder.meli_shipment): + shipid = sorder.meli_shipment.id + if ( (not shipid) and len(sorder.meli_orders) ): + shipment = shipment_obj.search([('shipping_id','=',sorder.meli_orders[0].shipping_id)]) + if (shipment and shipment.status=="ready_to_ship"): + shipid = shipment.id + else: + continue; + + if (shipid): + #shipment = shipment_obj.browse(shipid) + #shipment.update() + shipment_ids.append(shipid) + + return self.shipment_print_report(shipment_ids=shipment_ids,meli=meli,config=config,include_ready_to_print=self.include_ready_to_print) + + def shipment_stock_picking_print(self, context=None, meli=None, config=None): _logger.info("shipment_stock_picking_print") context = context or self.env.context diff --git a/views/orders_view.xml b/views/orders_view.xml index 4e3624a0..af557334 100644 --- a/views/orders_view.xml +++ b/views/orders_view.xml @@ -83,6 +83,11 @@ invisible="meli_order_id==False" class="oe_stat_button" icon="fa-refresh"/> +