Skip to content

Commit

Permalink
Upgraded in Odoo 17.0.24.17 Closes #116
Browse files Browse the repository at this point in the history
  • Loading branch information
fabriciocosta committed Mar 14, 2024
1 parent 0db315e commit 541321b
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 6 deletions.
2 changes: 1 addition & 1 deletion __manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
16 changes: 16 additions & 0 deletions data/channel_marketplace.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<data noupdate="0">

<record id="meli_channel_mkt_marketplace" model="meli.channel.mkt">
<field name="name">MercadoLibre</field>
<field name="code">marketplace</field>
</record>

<record id="meli_channel_mkt_mshops" model="meli.channel.mkt">
<field name="name">MercadoShops</field>
<field name="code">mshops</field>
</record>

</data>
</odoo>
24 changes: 21 additions & 3 deletions models/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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!')
]
Expand Down
59 changes: 57 additions & 2 deletions models/shipment.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,32 @@ 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:
shipment_ids_from_pick.append(sale_order.meli_shipment.id)
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']

Expand All @@ -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
Expand Down
7 changes: 7 additions & 0 deletions views/orders_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@
invisible="meli_order_id==False"
class="oe_stat_button"
icon="fa-refresh"/>
<button name='meli_oerp_print' type="object"
string="Imprimir guia"
invisible="meli_order_id==False"
class="oe_stat_button"
icon="fa-print"/>
<field name="meli_orders" invisible="0"/>
<group>
<field name="meli_order"/>
Expand All @@ -93,6 +98,8 @@
<field name="meli_status" invisible="0"/>
<field name="meli_status_brief" invisible="0"/>
<field name="meli_shipment" invisible="0"/>
<field name="meli_shipment_pdf_file" invisible="0"/>
<field name="meli_shipment_pdf_filename" invisible="0"/>
<field name="meli_shipment_logistic_type" invisible="0"/>
<field name="meli_status_detail" invisible="0"/>
<field name="meli_total_amount" invisible="0"/>
Expand Down
12 changes: 12 additions & 0 deletions views/shipment_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,18 @@
<field name="target">new</field>
</record>


<record id="action_mercadolibre_sale_order_print" model="ir.actions.act_window">
<field name="name">Imprimir Guias de MercadoLibre (Ordenes)</field>
<field name="type">ir.actions.act_window</field>
<field name="binding_model_id" ref="model_sale_order" />
<field name="res_model">mercadolibre.shipment.print</field>
<field name="binding_type">action</field>
<field name="binding_view_types">list,form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>

<!--act_window id="action_mercadolibre_stock_picking_print"
name="Imprimir Guias de MercadoLibre (Inv.)"
binding_model="stock.picking"
Expand Down

0 comments on commit 541321b

Please sign in to comment.