|
@@ -405,24 +405,46 @@ class Purchases(http.Controller):
|
|
|
'''
|
|
|
Create purchase order from cart and return id
|
|
|
'''
|
|
|
- def create_purchase_order(self, supplier_id, cart_items, date_order, currency_id, pricelist_id, payment_term_id=None):
|
|
|
- return request.env['purchase.order'].create({
|
|
|
+ def create_purchase_order(
|
|
|
+ self,
|
|
|
+ supplier_id,
|
|
|
+ cart_items,
|
|
|
+ date_order,
|
|
|
+ currency_id,
|
|
|
+ pricelist_id,
|
|
|
+ payment_term_id=None
|
|
|
+ ):
|
|
|
+
|
|
|
+ def get_product_obj(product_id):
|
|
|
+ return request.env['product.product'].browse(product_id)
|
|
|
+
|
|
|
+ lines = []
|
|
|
+
|
|
|
+ for item in cart_items:
|
|
|
+ product = get_product_obj(item.get('id'))
|
|
|
+
|
|
|
+ lines += [[0, False, {
|
|
|
+ 'name': item.get('name'),
|
|
|
+ 'date_planned': date_order,
|
|
|
+ 'product_id': product.id,
|
|
|
+ 'product_qty': float(item.get('quantity')),
|
|
|
+ 'price_unit': float(item.get('price')),
|
|
|
+ 'product_uom': product.uom_id.id
|
|
|
+ }]]
|
|
|
+
|
|
|
+ values = {
|
|
|
'name': '/',
|
|
|
'partner_id': supplier_id,
|
|
|
- 'order_line': [[0, False, {
|
|
|
- 'name': line.get('name'),
|
|
|
- 'date_planned': date_order,
|
|
|
- 'product_id': int(line.get('id')),
|
|
|
- 'product_qty': float(line.get('quantity')),
|
|
|
- 'price_unit': float(line.get('price'))
|
|
|
- }] for line in cart_items],
|
|
|
+ 'order_line': lines,
|
|
|
'date_order': datetime.utcnow().strftime(DATETIME_FORMAT),
|
|
|
'currency_id': currency_id,
|
|
|
'pricelist_id': pricelist_id,
|
|
|
'payment_term_id': payment_term_id,
|
|
|
'location_id': self.get_stock_location_id(),
|
|
|
'invoice_method': 'order'
|
|
|
- })
|
|
|
+ }
|
|
|
+
|
|
|
+ return request.env['purchase.order'].create(values)
|
|
|
|
|
|
'''
|
|
|
Confirm purchase order
|
|
@@ -442,7 +464,14 @@ class Purchases(http.Controller):
|
|
|
'''
|
|
|
Create invoice
|
|
|
'''
|
|
|
- def create_invoice(self, supplier_id, cart_items, currency_id, payment_term_id=None):
|
|
|
+ def create_invoice(
|
|
|
+ self,
|
|
|
+ supplier_id,
|
|
|
+ cart_items,
|
|
|
+ currency_id,
|
|
|
+ payment_term_id=None,
|
|
|
+ supplier_invoice_number=None
|
|
|
+ ):
|
|
|
partner = request.env['res.partner'].browse(supplier_id)
|
|
|
journal = request.env['account.journal'].search([('type', 'in', ['purchase']), ('company_id', '=', partner.company_id.id)])
|
|
|
|
|
@@ -459,6 +488,7 @@ class Purchases(http.Controller):
|
|
|
'journal_id': journal.id,
|
|
|
'currency_id': currency_id,
|
|
|
'payment_term': payment_term_id,
|
|
|
+ 'supplier_invoice_number': supplier_invoice_number,
|
|
|
'type': 'in_invoice'
|
|
|
})
|
|
|
|
|
@@ -750,8 +780,11 @@ class Purchases(http.Controller):
|
|
|
self.make_info_log('Purchase order confirmed')
|
|
|
|
|
|
invoice = purchase_order.invoice_ids
|
|
|
+ invoice.write({
|
|
|
+ 'supplier_invoice_number': kw.get('supplierInvoiceNumber', None)
|
|
|
+ })
|
|
|
else:
|
|
|
- invoice = self.create_invoice(kw.get('supplierId'), kw.get('items'), currency_id, kw.get('paymentTermId'))
|
|
|
+ invoice = self.create_invoice(kw.get('supplierId'), kw.get('items'), currency_id, kw.get('paymentTermId'), kw.get('supplierInvoiceNumber', None))
|
|
|
self.make_info_log('Invoice created')
|
|
|
|
|
|
invoice_ids = invoice.mapped(lambda x: x.id)
|