|
@@ -16,6 +16,24 @@ class Purchases(http.Controller):
|
|
|
def get_server_date(self):
|
|
|
return datetime.now().strftime('%Y-%m-%d')
|
|
|
|
|
|
+ '''
|
|
|
+ Get current user information
|
|
|
+ '''
|
|
|
+ def get_user(self):
|
|
|
+ user = request.env.user
|
|
|
+
|
|
|
+ return {
|
|
|
+ 'id': user.id,
|
|
|
+ 'name': user.name,
|
|
|
+ 'displayName': user.display_name,
|
|
|
+ 'currency': {
|
|
|
+ 'id': user.company_id.currency_id.id,
|
|
|
+ 'name': user.company_id.currency_id.name,
|
|
|
+ 'displayName': user.company_id.currency_id.display_name,
|
|
|
+ 'symbol': user.company_id.currency_id.symbol
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
def get_currencies(self):
|
|
|
return [{
|
|
|
'id': currency.id,
|
|
@@ -127,26 +145,62 @@ class Purchases(http.Controller):
|
|
|
} for variant in product.product_variant_ids if variant.active]
|
|
|
} for product in request.env['product.template'].search([('purchase_ok', '=', True), ('active', '=', True)])]
|
|
|
|
|
|
+ '''
|
|
|
+ Get all incoming and active picking types
|
|
|
+ '''
|
|
|
+ def get_picking_types(self):
|
|
|
+ return [{
|
|
|
+ 'id': picking_type.id,
|
|
|
+ 'name': picking_type.name,
|
|
|
+ 'displayName': picking_type.display_name
|
|
|
+ } for picking_type in request.env['stock.picking.type'].search([('code', '=', 'incoming'), ('active', '=', True)])]
|
|
|
+
|
|
|
+ '''
|
|
|
+ Get all active payment terms
|
|
|
+ '''
|
|
|
+ def get_payment_terms(self):
|
|
|
+ return [{
|
|
|
+ 'id': payment_term.id,
|
|
|
+ 'name': payment_term.name,
|
|
|
+ 'displayName': payment_term.display_name,
|
|
|
+ 'lines': [{
|
|
|
+ 'id': line.id,
|
|
|
+ 'days': line.days,
|
|
|
+ 'days2': line.days2,
|
|
|
+ 'value': line.value,
|
|
|
+ 'value_amount': line.value_amount
|
|
|
+ } for line in payment_term.line_ids]
|
|
|
+ } for payment_term in request.env['account.payment.term'].search([('active', '=', True)])]
|
|
|
+
|
|
|
'''
|
|
|
Make JSON response to send
|
|
|
'''
|
|
|
def make_response(self, data, status=200):
|
|
|
return Response(json.dumps(data), status=status, content_type='application/json')
|
|
|
|
|
|
+ '''
|
|
|
+ '''
|
|
|
+ def make_info_log(self, log):
|
|
|
+ LOGGER.info(log)
|
|
|
+
|
|
|
'''
|
|
|
New purchase resource route
|
|
|
'''
|
|
|
@http.route('/eiru_purchases/new', auth='user', methods=['GET'], cors='*')
|
|
|
def new_purchase(self, **kw):
|
|
|
+ self.make_info_log('sending json response')
|
|
|
+
|
|
|
return self.make_response({
|
|
|
'date': self.get_server_date(),
|
|
|
+ 'user': self.get_user(),
|
|
|
'currencies': self.get_currencies(),
|
|
|
'journals': self.get_journals(),
|
|
|
'suppliers': self.get_suppliers(),
|
|
|
- 'products': self.get_products()
|
|
|
+ 'products': self.get_products(),
|
|
|
+ 'pickingTypes': self.get_picking_types(),
|
|
|
+ 'paymentTerms': self.get_payment_terms()
|
|
|
})
|
|
|
|
|
|
-
|
|
|
'''
|
|
|
Create purchase resource route
|
|
|
'''
|