diff options
| -rwxr-xr-x | fixco_custom/models/detail_order.py | 26 | ||||
| -rwxr-xr-x | fixco_custom/models/sale.py | 33 | ||||
| -rwxr-xr-x | fixco_custom/views/sale_order.xml | 28 |
3 files changed, 71 insertions, 16 deletions
diff --git a/fixco_custom/models/detail_order.py b/fixco_custom/models/detail_order.py index 6cf291c..a01e7a1 100755 --- a/fixco_custom/models/detail_order.py +++ b/fixco_custom/models/detail_order.py @@ -206,8 +206,20 @@ class DetailOrder(models.Model): return partner.id def prepare_data_so(self, json_data): + order = json_data.get('data', [{}])[0] date_str = json_data.get('data', [{}])[0].get('promisedToShipBefore') deadline_date = False + partner = self.get_partner(json_data.get('data', {})[0].get('shopId')) + if partner == 281: + payment_info = order.get('paymentInfo', {}) + total_discounts = payment_info.get('totalDiscounts', 0) or 0 + discount_shipping = payment_info.get('totalDiscountShipping', 0) or 0 + total_tax = payment_info.get('totalTaxation', 0) or 0 + total_shipping_fee = payment_info.get('totalShippingFee', 0) or 0 + if discount_shipping > 0: + total_discounts += discount_shipping + + total_discounts = -total_discounts if date_str: # utc_dt = datetime.strptime( @@ -231,7 +243,13 @@ class DetailOrder(models.Model): 'source': 'ginee', 'channel': json_data.get('data', {})[0].get('channel'), 'deadline_date': deadline_date, + } + if partner == 281: + data['marketplace_discount'] = total_discounts + data['marketplace_tax'] = total_tax + data['delivery_amount'] = total_shipping_fee + return data def _combine_order_items(self, items, lazada_id): @@ -285,6 +303,10 @@ class DetailOrder(models.Model): limit=1 ) + if product.id == 6031: + product.id = 5792 + product_not_found = True + if product and item.get('masterSkuType') == 'BUNDLE': order_lines.append((0, 0, { 'display_type': 'line_note', @@ -332,12 +354,16 @@ class DetailOrder(models.Model): })) continue + partner = self.get_partner(json_data.get('data', {})[0].get('shopId')) + # Regular product line line_data = { 'product_id': product.id if product else 5792, 'product_uom_qty': combined_item['quantity'], 'price_unit': combined_item['actualPrice'], } + if partner == 281: + line_data['tax_id'] = [(5, 0, 0)] if not product: line_data['name'] = f"{sku} ({combined_item['productName']})" diff --git a/fixco_custom/models/sale.py b/fixco_custom/models/sale.py index 90cc581..ab03acd 100755 --- a/fixco_custom/models/sale.py +++ b/fixco_custom/models/sale.py @@ -1,5 +1,8 @@ from odoo import api, fields, models, _ from odoo.exceptions import UserError +import logging + +_logger = logging.getLogger(__name__) class SaleOrder(models.Model): @@ -28,6 +31,31 @@ class SaleOrder(models.Model): ) uangmuka_exist = fields.Boolean(string='Uang Muka Exist', copy=False) + delivery_amount = fields.Monetary("Delivery Amount", currency_field='currency_id') + + marketplace_discount = fields.Monetary( + string="Marketplace Discount", + currency_field='currency_id' + ) + + marketplace_tax = fields.Monetary( + string="Marketplace Tax", + currency_field='currency_id' + ) + + @api.depends('order_line.price_total', 'delivery_amount') + def _amount_all(self): + super()._amount_all() + + for order in self: + if order.partner_id.id == 281: + subtotal = sum(line.price_subtotal for line in order.order_line) + tax = order.marketplace_tax + delivery = order.delivery_amount or 0 + discount = order.marketplace_discount or 0 + + order.amount_total = subtotal + tax + delivery + discount + @api.depends( 'order_line.price_unit', 'order_line.product_uom_qty', @@ -35,6 +63,11 @@ class SaleOrder(models.Model): ) def _compute_total_discount(self): for order in self: + if order.partner_id.id == 281: + # Biar gk error + order.total_discount = order.total_discount + continue + total = 0.0 for line in order.order_line: if line.discount: diff --git a/fixco_custom/views/sale_order.xml b/fixco_custom/views/sale_order.xml index 2d2a923..11ec935 100755 --- a/fixco_custom/views/sale_order.xml +++ b/fixco_custom/views/sale_order.xml @@ -7,25 +7,15 @@ <field name="inherit_id" ref="sale.view_order_form"/> <field name="arch" type="xml"> <xpath expr="//button[@name='action_view_invoice']" position="before"> - <button type="object" - name="action_view_related_payment" - class="oe_stat_button" - icon="fa-pencil-square-o" - attrs="{'invisible': [('count_payment', '=', 0)]}" groups="base.group_user"> + <button type="object" name="action_view_related_payment" class="oe_stat_button" icon="fa-pencil-square-o" attrs="{'invisible': [('count_payment', '=', 0)]}" groups="base.group_user"> <field name="count_payment" widget="statinfo" string="Payments"/> </button> - <button type="object" - name="action_view_related_journals" - class="oe_stat_button" - icon="fa-book" - attrs="{'invisible': [('count_journals', '=', 0)]}" groups="base.group_user"> + <button type="object" name="action_view_related_journals" class="oe_stat_button" icon="fa-book" attrs="{'invisible': [('count_journals', '=', 0)]}" groups="base.group_user"> <field name="count_journals" widget="statinfo" string="Journals"/> </button> </xpath> <button id="action_confirm" position="after"> - <button name="open_form_uangmuka_penjualan" - string="UangMuka" - type="object" attrs="{'invisible': [('state', '!=', 'sale')]}"/> + <button name="open_form_uangmuka_penjualan" string="UangMuka" type="object" attrs="{'invisible': [('state', '!=', 'sale')]}"/> </button> <field name="tag_ids" position="after"> <field name="carrier"/> @@ -33,8 +23,14 @@ <field name="partner_id" position="after"> <field name="address"/> </field> + <field name="amount_tax" position="before"> + <field name="marketplace_tax" attrs="{'invisible': [('partner_id','!=',281)]}"/> + </field> + <field name="amount_tax" position="after"> - <field name="total_discount"/> + <field name="delivery_amount" attrs="{'invisible': [('partner_id','!=',281)]}"/> + <field name="total_discount" /> + <field name="marketplace_discount" attrs="{'invisible': [('partner_id','!=',281)]}"/> </field> <field name="client_order_ref" position="after"> <field name="order_reference" attrs="{'required': [('source', '!=', 'manual')]}"/> @@ -50,7 +46,7 @@ </field> </record> </data> - + <data> <record id="sale_order_tree_inherit" model="ir.ui.view"> <field name="name">Sale Order</field> @@ -68,7 +64,7 @@ </field> </record> </data> - + <data> <record id="sale_order_quotation_tree_inherit" model="ir.ui.view"> <field name="name">Quotations</field> |
