205
205
so_obj.write(cr, uid, order.id, {'need_to_update': False})
209
def _create_magento_invoice(self, cr, uid, order, conn, ext_id, context=None):
210
""" Creation of an invoice on Magento."""
211
cr.execute("select account_invoice.id "
212
"from account_invoice "
213
"inner join sale_order_invoice_rel "
214
"on invoice_id = account_invoice.id "
215
"where order_id = %s" % order.id)
216
resultset = cr.fetchone()
218
if resultset and len(resultset) == 1:
219
invoice = self.pool.get("account.invoice").browse(
220
cr, uid, resultset[0], context=context)
221
if (invoice.amount_total == order.amount_total and
222
not invoice.magento_ref):
224
magento_invoice_ref = conn.call(
225
'sales_order_invoice.create',
226
[order.magento_incrementid,
228
_("Invoice Created"),
230
order.shop_id.allow_magento_notification])
231
self.pool.get("account.invoice").write(
234
{'magento_ref': magento_invoice_ref,
235
'origin': magento_invoice_ref})
236
self.log(cr, uid, order.id,
237
"created Magento invoice for order %s" %
241
self.log(cr, uid, order.id,
242
"failed to create Magento invoice for order %s" %
244
# TODO make sure that's because Magento invoice already
245
# exists and then re-attach it!
209
248
def update_shop_orders(self, cr, uid, order, ext_id, context=None):
210
249
if context is None: context = {}
213
if order.shop_id.allow_magento_order_status_push:
252
if order.shop_id.allow_magento_order_status_push:
215
254
conn = context.get('conn_obj', False)
216
logger = netsvc.Logger()
217
255
status = ORDER_STATUS_MAPPING.get(order.state, False)
219
result['status_change'] = conn.call('sales_order.addComment', [ext_id, status, '', order.shop_id.allow_magento_notification])
220
# If status has changed into OERP and the order need_to_update, then we consider the update is done
257
result['status_change'] = conn.call(
258
'sales_order.addComment',
260
order.shop_id.allow_magento_notification])
261
# If status has changed into OERP and the order need_to_update,
262
# then we consider the update is done
221
263
# remove the 'need_to_update': True
222
264
if order.need_to_update:
223
self.pool.get('sale.order').write(cr, uid, order.id, {'need_to_update': False})
225
#creation of Magento invoice eventually:
226
cr.execute("select account_invoice.id from account_invoice inner join sale_order_invoice_rel on invoice_id = account_invoice.id where order_id = %s" % order.id)
227
resultset = cr.fetchone()
228
if resultset and len(resultset) == 1:
229
invoice = self.pool.get("account.invoice").browse(cr, uid, resultset[0])
230
if invoice.amount_total == order.amount_total and not invoice.magento_ref:
232
result['magento_invoice_ref'] = conn.call('sales_order_invoice.create', [order.magento_incrementid, [], _("Invoice Created"), True, order.shop_id.allow_magento_notification])
233
self.pool.get("account.invoice").write(cr, uid, invoice.id, {'magento_ref': result['magento_invoice_ref'], 'origin': result['magento_invoice_ref']})
234
self.log(cr, uid, order.id, "created Magento invoice for order %s" % (order.id,))
236
self.log(cr, uid, order.id, "failed to create Magento invoice for order %s" % (order.id,))
237
logger.notifyChannel('ext synchro', netsvc.LOG_DEBUG, "failed to create Magento invoice for order %s" % (order.id,))
238
#TODO make sure that's because Magento invoice already exists and then re-attach it!
265
self.pool.get('sale.order').write(
266
cr, uid, order.id, {'need_to_update': False})
268
self._create_magento_invoice(
269
cr, uid, order, conn, ext_id, context=context)
244
272
def _sale_shop(self, cr, uid, callback, context=None):
245
273
if context is None: