diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2024-10-23 10:22:26 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2024-10-23 10:22:26 +0700 |
| commit | 70a6cf87d721e9e6c78d27a9e9ef4168ad96fac7 (patch) | |
| tree | e3d609724a143db1f8a7ae34caec537da032bec4 | |
| parent | 943ee3ca2e3b8469d1f3969fa6ea45710e532fc0 (diff) | |
| parent | 25645d93db289ea4855486630dba8d578efb2851 (diff) | |
Merge branch 'production' into feature/generate_url
| -rw-r--r-- | indoteknik_api/models/res_users.py | 2 | ||||
| -rw-r--r-- | indoteknik_custom/models/account_move_due_extension.py | 7 | ||||
| -rwxr-xr-x | indoteknik_custom/models/product_template.py | 1 | ||||
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 9 | ||||
| -rw-r--r-- | indoteknik_custom/models/stock_picking.py | 82 | ||||
| -rw-r--r-- | indoteknik_custom/views/account_move_views.xml | 8 | ||||
| -rw-r--r-- | indoteknik_custom/views/dunning_run.xml | 1 |
7 files changed, 93 insertions, 17 deletions
diff --git a/indoteknik_api/models/res_users.py b/indoteknik_api/models/res_users.py index 534898e1..2751ca7a 100644 --- a/indoteknik_api/models/res_users.py +++ b/indoteknik_api/models/res_users.py @@ -48,7 +48,7 @@ class ResUsers(models.Model): 'street': user.street or '', 'street2': user.street2 or '', 'city': None, - 'state_id': None, + 'state_id': 0, 'district': None, 'sub_district': None, 'zip': user.zip or '', diff --git a/indoteknik_custom/models/account_move_due_extension.py b/indoteknik_custom/models/account_move_due_extension.py index 23f8888c..6fc58cdd 100644 --- a/indoteknik_custom/models/account_move_due_extension.py +++ b/indoteknik_custom/models/account_move_due_extension.py @@ -1,6 +1,6 @@ from odoo import models, api, fields from odoo.exceptions import AccessError, UserError, ValidationError -from datetime import timedelta, date +from datetime import timedelta, date, datetime import logging _logger = logging.getLogger(__name__) @@ -31,7 +31,8 @@ class DueExtension(models.Model): ('21', '21 Hari'), ], string='Day Extension', help='Menambah Due Date yang sudah limit dari hari ini', tracking=True) counter = fields.Integer(string="Counter", compute='_compute_counter') - + approve_by = fields.Many2one('res.users', string="Approve By", readonly=True) + date_approve = fields.Datetime(string="Date Approve", readonly=True) def _compute_counter(self): for due in self: due.counter = due.partner_id.counter @@ -96,6 +97,8 @@ class DueExtension(models.Model): sales.action_confirm() self.order_id.due_id = self.id + self.approve_by = self.env.user.id + self.date_approve = datetime.utcnow() template = self.env.ref('indoteknik_custom.mail_template_due_extension_approve') template.send_mail(self.id, force_send=True) diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py index af7f98cd..2ca4925b 100755 --- a/indoteknik_custom/models/product_template.py +++ b/indoteknik_custom/models/product_template.py @@ -405,6 +405,7 @@ class ProductProduct(models.Model): continue if any(variant.active for variant in variants): product_template.unpublished = False + variants.unpublished = False def update_internal_reference_variants(self, limit=100): variants = self.env['product.product'].search([ diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index 891482cb..1ad08154 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -873,17 +873,16 @@ class SaleOrder(models.Model): }).send() def validate_different_vendor(self): - if self.vendor_approval_id and self.vendor_approval: - return False - - different_vendor = self.order_line.filtered(lambda l: l.vendor_id and l.vendor_md_id and l.vendor_id.id != l.vendor_md_id.id) - if self.vendor_approval_id and self.vendor_approval_id.state == 'draft': raise UserError('SO ini sedang dalam review Vendor Approval') if self.vendor_approval_id and self.vendor_approval_id.state == 'cancel': raise UserError('Vendor Approval SO ini Di Reject') + if self.vendor_approval_id and self.vendor_approval_id.state == 'done': + return False + + different_vendor = self.order_line.filtered(lambda l: l.vendor_id and l.vendor_md_id and l.vendor_id.id != l.vendor_md_id.id) if different_vendor: vendor_approval = self.env['vendor.approval'].create({ 'order_id': self.id, diff --git a/indoteknik_custom/models/stock_picking.py b/indoteknik_custom/models/stock_picking.py index a5482f9d..2a73d631 100644 --- a/indoteknik_custom/models/stock_picking.py +++ b/indoteknik_custom/models/stock_picking.py @@ -3,7 +3,7 @@ from odoo.exceptions import AccessError, UserError, ValidationError from odoo.tools.float_utils import float_is_zero from datetime import datetime from itertools import groupby -import pytz, datetime +import pytz, datetime, requests, json class StockPicking(models.Model): @@ -107,6 +107,51 @@ class StockPicking(models.Model): ('done', 'Done'), ('cancel', 'Cancelled'), ], string='Status Reserve', readonly=True, tracking=True, help="The current state of the stock picking.") + + def action_send_to_biteship(self): + url = "https://api.biteship.com/v1/orders" + + api_key = "biteship_test.eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiSW5kb3Rla25payIsInVzZXJJZCI6IjY3MTViYTJkYzVkMjdkMDAxMjRjODk2MiIsImlhdCI6MTcyOTQ5ODAwMX0.L6C73couP4-cgVEfhKI2g7eMCMo3YOFSRZhS-KSuHNA" + + items_data = [] + for item in self.items: + items_data.append({ + "name": item.name, + "description": item.description, + "category": item.category, + "value": item.value, + "quantity": item.quantity, + "weight": item.weight + }) + + payload = { + "shipper_contact_name": self.carrier_id.pic_name or '', + "shipper_contact_phone": self.carrier_id.pic_phone or '', + # "shipper_contact_email": "sales@indoteknik.co.id", + "shipper_organization": self.carrier_id.name, + "origin_contact_name": "PT. Indoteknik Dotcom Gemilang", + "origin_contact_phone": "081717181922", + "origin_address": "Jl. Bandengan Utara Komp A & BRT. Penjaringan, Kec. Penjaringan, Jakarta (BELAKANG INDOMARET) KOTA JAKARTA UTARA PENJARINGAN", + "origin_postal_code": "14440", + "destination_contact_name": self.real_shipping_id.name, + "destination_contact_phone": self.real_shipping_id.phone or self.real_shipping_id.mobile, + "destination_contact_email": self.real_shipping_id.email or '', + "destination_address": self.real_shipping_id.street, + "destination_postal_code": self.real_shipping_id.zip, + "items": items_data + } + + headers = { + "Authorization": f"Bearer {api_key}", + "Content-Type": "application/json" + } + + response = requests.post(url, headers=headers, data=json.dumps(payload)) + + if response.status_code == 201: + return response.json() + else: + raise UserError(f"Error saat mengirim ke Biteship: {response.content}") @api.constrains('driver_departure_date') def constrains_driver_departure_date(self): @@ -145,18 +190,39 @@ class StockPicking(models.Model): return res + # def check_state_reserve(self): + # do = self.search([ + # ('state', 'not in', ['cancel', 'draft', 'done']), + # ('picking_type_code', '=', 'outgoing') + # ]) + + # for rec in do: + # rec.state_reserve = 'ready' + # rec.date_reserved = datetime.datetime.utcnow() + + # for line in rec.move_ids_without_package: + # if line.product_uom_qty > line.reserved_availability: + # rec.state_reserve = 'waiting' + # rec.date_reserved = '' + # break + def check_state_reserve(self): - do = self.search([ + picking = self.search([ ('state', 'not in', ['cancel', 'draft', 'done']), ('picking_type_code', '=', 'outgoing') ]) + + for data in picking: + fullfilment = self.env['sales.order.fullfillment'].search([ + ('sales_order_id', '=', data.sale_id.id) + ]) - for rec in do: - rec.state_reserve = 'ready' - - for line in rec.move_ids_without_package: - if line.product_uom_qty > line.reserved_availability: - rec.state_reserve = 'waiting' + data.state_reserve = 'ready' + data.date_reserved = datetime.datetime.utcnow() + for rec in fullfilment: + if rec.reserved_from not in ['Inventory On Hand', 'Reserved from stock', 'Free Stock']: + data.state_reserve = 'waiting' + data.date_reserved = '' break def _create_approval_notification(self, approval_role): diff --git a/indoteknik_custom/views/account_move_views.xml b/indoteknik_custom/views/account_move_views.xml index 4acafb14..da25636e 100644 --- a/indoteknik_custom/views/account_move_views.xml +++ b/indoteknik_custom/views/account_move_views.xml @@ -12,6 +12,10 @@ <field name="description"/> <field name="approval_status"/> <field name="is_approve"/> + <field name="approve_by" optional="hide"/> + <field name="date_approve" optional="hide"/> + <field name="create_uid" optional="hide"/> + <field name="create_date" optional="hide"/> </tree> </field> </record> @@ -58,12 +62,14 @@ <group> <field name="partner_id" readonly="1"/> <field name="day_extension" attrs="{'readonly': [('is_approve', '=', True)]}"/> + <field name="order_id" readonly="1"/> </group> <group> <field name="is_approve" readonly="1"/> - <field name="order_id" readonly="1"/> <field name="counter" readonly="1"/> <field name="approval_status" readonly="1"/> + <field name="approve_by" readonly="1"/> + <field name="date_approve" readonly="1"/> </group> </group> <group> diff --git a/indoteknik_custom/views/dunning_run.xml b/indoteknik_custom/views/dunning_run.xml index 522be8c9..2117a7bb 100644 --- a/indoteknik_custom/views/dunning_run.xml +++ b/indoteknik_custom/views/dunning_run.xml @@ -14,6 +14,7 @@ <field name="date_terima_tukar_faktur"/> <field name="shipper_faktur_id"/> <field name="grand_total"/> + <field name="create_uid" optional="hide"/> </tree> </field> </record> |
