Best Python code snippet using localstack_python
sale_order.py
Source:sale_order.py
1from odoo import models, fields, api2import logging3from datetime import datetime, date4_logger = logging.getLogger("==== Sale Order (Unifonic message) ====")5class SaleOrder(models.Model):6 _inherit = "sale.order"7 @api.multi8 def write(self, vals):9 current_date = date.today()10 current_datetime = datetime.now()11 res = super(SaleOrder, self).write(vals)12 state = vals.get("state")13 if state:14 instance_id = self.env["sms.instance"].search([("provider", "=", "unifonic_sms")])15 if instance_id:16 message = ""17 to_number = self.partner_id.phone18 if not to_number and self.partner_id.mobile:19 to_number = self.partner_id.mobile20 elif not to_number and self.partner_invoice_id.phone:21 to_number = self.partner_invoice_id.phone22 elif not to_number and self.partner_invoice_id.mobile:23 to_number = self.partner_invoice_id.mobile24 if not to_number:25 _logger.info("Customer number is not available for this order: {}".format(self.name))26 order_detail = "Order is {} and customer number is not available".format(self.name)27 self.env["msg.error.log"].create({"sms_instance_id": instance_id.id,28 "datetime": current_datetime,29 "process": "Send SMS",30 "order_detail": order_detail})31 else:32 tracking_number = ""33 tracking_url = ""34 if state == "sent":35 if instance_id.for_sent:36 message = instance_id.sent_msg37 elif state == "sale":38 if instance_id.for_sale:39 message = instance_id.sale_msg40 elif state == "done":41 if instance_id.for_done:42 message = instance_id.done_msg43 elif state == "cancel":44 if instance_id.for_cancel:45 message = instance_id.cancel_msg46 for picking_id in self.picking_ids:47 if picking_id.state == "done":48 tracking_number = picking_id.carrier_tracking_ref49 tracking_url = "{}{}".format(picking_id.carrier_id.tracking_url,50 picking_id.carrier_tracking_ref)51 break52 if message:53 message = message.replace("{{order_number}}", self.name)54 message = message.replace("{{total_amount}}", str(self.amount_total))55 message = message.replace("{{state}}", self.state.capitalize())56 message = message.replace("{{tracking_number}}", tracking_number or "")57 message = message.replace("{{carrier_name}}", self.carrier_id and self.carrier_id.name or "")58 message = message.replace("{{tracking_url}}", tracking_url or "")59 message = message.replace("{{confirmation_date}}", self.confirmation_date or "")60 message = message.replace("{{marketing_url}}", instance_id.marketing_url or "")61 self.env["msg.records"].create({"to_number": to_number,62 "message": message,63 "state": "draft",64 "current_date": current_date})65 return res66 @api.multi67 def send_msg_for_draft(self):68 current_date = date.today()69 current_datetime = datetime.now()70 state = self.state71 if state:72 instance_id = self.env["sms.instance"].search([("provider", "=", "unifonic_sms")])73 if instance_id:74 message = ""75 to_number = self.partner_id.phone76 if not to_number and self.partner_id.mobile:77 to_number = self.partner_id.mobile78 elif not to_number and self.partner_invoice_id.phone:79 to_number = self.partner_invoice_id.phone80 elif not to_number and self.partner_invoice_id.mobile:81 to_number = self.partner_invoice_id.mobile82 if not to_number:83 _logger.info("Customer number is not available for this order: {}".format(self.name))84 order_detail = "Order is {} and customer number is not available".format(self.name)85 self.env["msg.error.log"].create({"sms_instance_id": instance_id.id,86 "datetime": current_datetime,87 "process": "Send SMS",88 "order_detail": order_detail})89 else:90 if state == "draft":91 if instance_id.for_draft:92 message = instance_id.draft_msg93 if message:94 message = message.replace("{{order_number}}", self.name)95 message = message.replace("{{total_amount}}", str(self.amount_total))96 message = message.replace("{{state}}", self.state.capitalize())97 message = message.replace("{{confirmation_date}}", self.confirmation_date or "")98 message = message.replace("{{marketing_url}}", instance_id.marketing_url or "")99 self.env["msg.records"].create({"to_number": to_number,100 "message": message,101 "state": "draft",...
jsmath.py
Source:jsmath.py
...18 'enumerable': False,19 'configurable': False})20class MathFunctions:21 def abs(x):22 a = x.to_number().value23 if a!=a: # it must be a nan24 return NaN25 return abs(a)26 def acos(x):27 a = x.to_number().value28 if a!=a: # it must be a nan29 return NaN30 try:31 return math.acos(a)32 except:33 return NaN34 def asin(x):35 a = x.to_number().value36 if a!=a: # it must be a nan37 return NaN38 try:39 return math.asin(a)40 except:41 return NaN42 def atan(x):43 a = x.to_number().value44 if a!=a: # it must be a nan45 return NaN46 return math.atan(a)47 def atan2(y, x):48 a = x.to_number().value49 b = y.to_number().value50 if a!=a or b!=b: # it must be a nan51 return NaN52 return math.atan2(b, a)53 def ceil(x):54 a = x.to_number().value55 if a!=a: # it must be a nan56 return NaN57 return math.ceil(a)58 def floor(x):59 a = x.to_number().value60 if a!=a: # it must be a nan61 return NaN62 return math.floor(a)63 def round(x):64 a = x.to_number().value65 if a!=a: # it must be a nan66 return NaN67 return round(a)68 def sin(x):69 a = x.to_number().value70 if a!=a: # it must be a nan71 return NaN72 return math.sin(a)73 def cos(x):74 a = x.to_number().value75 if a!=a: # it must be a nan76 return NaN77 return math.cos(a)78 def tan(x):79 a = x.to_number().value80 if a!=a: # it must be a nan81 return NaN82 return math.tan(a)83 def log(x):84 a = x.to_number().value85 if a!=a: # it must be a nan86 return NaN87 try:88 return math.log(a)89 except:90 return NaN91 def exp(x):92 a = x.to_number().value93 if a!=a: # it must be a nan94 return NaN95 return math.exp(a)96 def pow(x, y):97 a = x.to_number().value98 b = y.to_number().value99 if a!=a or b!=b: # it must be a nan100 return NaN101 try:102 return a**b103 except:104 return NaN105 def sqrt(x):106 a = x.to_number().value107 if a!=a: # it must be a nan108 return NaN109 try:110 return a**0.5111 except:112 return NaN113 def min():114 if not len(arguments):115 return -Infinity116 lis = tuple(e.to_number().value for e in arguments.to_list())117 if any(e!=e for e in lis): # we dont want NaNs118 return NaN119 return min(*lis)120 def max():121 if not len(arguments):122 return -Infinity123 lis = tuple(e.to_number().value for e in arguments.to_list())124 if any(e!=e for e in lis): # we dont want NaNs125 return NaN126 return max(*lis)127 def random():128 return random.random()...
whatsapp_message_wizard.py
Source:whatsapp_message_wizard.py
1from odoo import models, fields, api2class WhatsappMessageWizard(models.TransientModel):3 _name = "whatsapp.message.wizard"4 to_number = fields.Char("To Number")5 msg = fields.Text("Message")6 picking_ids = fields.Many2many("stock.picking")7 picking_id = fields.Many2one("stock.picking")8 message_type = fields.Selection([("tracking", "Tracking"), ("bank_details", "Bank Details")])9 @api.model10 def default_get(self, fields_list):11 res = super(WhatsappMessageWizard, self).default_get(fields_list)12 order_id = self.env["sale.order"].browse(self._context.get('active_id'))13 if 'picking_ids' in fields_list:14 res.update({'picking_ids': [(6, 0, order_id.picking_ids.ids)]})15 if "to_number" in fields_list:16 to_number = order_id.partner_id.phone17 if not to_number and order_id.partner_id.mobile:18 to_number = order_id.partner_id.mobile19 elif not to_number and order_id.partner_invoice_id.phone:20 to_number = order_id.partner_invoice_id.phone21 elif not to_number and order_id.partner_invoice_id.mobile:22 to_number = order_id.partner_invoice_id.mobile23 if to_number:24 dst_number = to_number25 dst_number = dst_number.lstrip("0")26 dst_number = dst_number.lstrip("+")27 dst_number = dst_number.lstrip("966")28 dst_number = "+966{}".format(dst_number)29 res.update({"to_number": dst_number})30 return res31 @api.onchange('picking_id')32 def _onchange_picking_id(self):33 if self.picking_id:34 url = self.picking_id.carrier_id.tracking_url35 tracking_number = self.picking_id.carrier_tracking_ref36 if url and tracking_number:37 tracking_url = "{}{}".format(url, tracking_number)38 self.msg = tracking_url39 @api.onchange("message_type")40 def _onchange_message_type(self):41 self.picking_id = False42 order_id = self.env["sale.order"].browse(self._context.get('active_id'))43 if self.message_type == "bank_details":44 self.msg = """عÙ
ÙÙÙا اÙعزÙز تÙ
استÙاÙ
Ø·Ùب٠رÙÙ
{} 45اÙرجاء تØÙÙ٠اÙÙ
بÙغ Ø®Ùا٠ا٠٢٤ ساع٠اÙÙادÙ
Ø© ÙØجز Ù
ÙتجاتÙÙ
٠تأÙÙد اÙØ·Ùب 46Ù
ؤسس٠ÙØ·Ù٠اÙÙ
Ùز٠47اÙبÙ٠اÙØ£ÙÙ٠اÙتجار٠481458127400010849Ø¢Ùبا٠50SA671000001458127400010851بÙ٠اÙراجØÙ :5216160801030460353Ø¢ÙباÙ54SA888000016160801030460355Ùارسا٠صÙر٠Ù
٠إÙصا٠اÙتØÙÙ٠اÙبÙÙ٠عاÙرÙÙ
00966920022468 ع٠طرÙ٠اÙÙاتس""".format(order_id.name,56 order_id.amount_total)57 elif self.message_type == "tracking":58 self.msg = ""59 @api.multi60 def send_whatsapp_message(self):61 url = 'https://web.whatsapp.com/send?phone='62 url += self.to_number + "&text=" + self.msg63 return {'type': 'ir.actions.act_url',64 'name': "Send Sale Order",65 'target': 'new',...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!