Skip to content

Commit

Permalink
[T7148]bad_connector_woocommerce:Improved the code as suggested in PR.
Browse files Browse the repository at this point in the history
  • Loading branch information
SIP authored and SIP committed Jan 4, 2024
1 parent 2a0e2df commit e38d018
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 15 deletions.
29 changes: 25 additions & 4 deletions bad_connector_woocommerce/models/sale_order/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,38 @@ class SaleOrder(models.Model):
string="WooCommerce Payment Mode",
readonly=True,
)

is_fully_returned = fields.Boolean(
string="Fully Returned",
compute="_compute_is_fully_returned",
store=True,
readonly=True,
)

@api.depends(
"order_line.qty_delivered", "order_line.product_uom_qty", "picking_ids"
)
# @api.depends("order_line.qty_delivered", "order_line.product_uom_qty",
# "picking_ids.move_ids.quantity_done")
# def _compute_is_fully_returned(self):
# for order in self:
# flag_fully_return = False
# related_pickings = order.picking_ids.filtered(
# lambda p: any(move.origin_returned_move_id for move in p.move_ids)
# )
# print(related_pickings, "oooooooooooooooooooooooooo related picking")

# is_fully_returned = all(
# all(
# move.quantity_done == order_line.product_uom_qty
# for order_line in order.order_line
# if move.origin_returned_move_id == order_line.product_id
# )
# for picking in related_pickings
# for move in picking.move_ids
# )

# if is_fully_returned:
# flag_fully_return = True

# order.is_fully_returned = flag_fully_return
@api.depends("order_line.qty_delivered", "order_line.product_uom_qty")
def _compute_is_fully_returned(self):
"""
Compute the 'is_fully_returned' field for the sale order.
Expand Down
21 changes: 16 additions & 5 deletions bad_connector_woocommerce/models/stock_picking/common.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging

from odoo import fields, models
from odoo import api, fields, models

from odoo.addons.component.core import Component

Expand All @@ -19,6 +19,17 @@ class StockPicking(models.Model):
is_refund = fields.Boolean(string="Refund Quantity With Amount")
sale_woo_binding_ids = fields.One2many(related="sale_id.woo_bind_ids")
return_picking_id = fields.Many2one("stock.picking", string="Original Picking")
is_return_stock_picking = fields.Boolean(
compute="_compute_is_return_stock_picking",
store=True,
)

@api.depends("move_ids_without_package")
def _compute_is_return_stock_picking(self):
for picking in self:
picking.is_return_stock_picking = any(
m.origin_returned_move_id for m in picking.move_ids_without_package
)

def export_refund(self, job_options=None):
"""Export Refund on WooCommerce"""
Expand Down Expand Up @@ -63,10 +74,10 @@ class WooStockPickingRefundAdapter(Component):
_woo_ext_id_key = "id"

def create(self, data):
"""
Overrides:This method overrides to use the Order Id in reasource_path
"""Inherited: Inherited this method due to create the resource_path to export
the refund
"""
resource_path = "{}/{}/refunds".format(self._woo_model, data["order_id"])
data.pop("order_id")
result = self._call(resource_path, data, http_method="post")
return result
self._woo_model = resource_path
return super(WooStockPickingRefundAdapter, self).create(data)
2 changes: 1 addition & 1 deletion bad_connector_woocommerce/models/stock_picking/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class WooStockPickingRefundBatchExporter(Component):

def _after_export(self, binding):
"""Update the Woocommerce status as Refunded of sale order."""
if binding.sale_id.is_fully_returned:
if not binding.sale_id.is_fully_returned:
return super(WooStockPickingRefundBatchExporter, self)._after_export(
binding
)
Expand Down
1 change: 0 additions & 1 deletion bad_connector_woocommerce/models/woo_backend/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,6 @@ def _domain_for_export_refund(self):
"""Domain to search WooCommerce Order Refunds"""
return [
("sale_id.woo_bind_ids.backend_id", "in", self.ids),
("is_return_picking", "=", True),
("is_refund", "=", True),
("woo_bind_ids", "=", False),
("sale_id.is_fully_returned", "=", False),
Expand Down
3 changes: 2 additions & 1 deletion bad_connector_woocommerce/tests/test_export_refund.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,8 @@ def test_export_refund(self):
return01.move_ids.quantity_done = 1
return01.button_validate()
self.assertTrue(
return01.is_return_picking, "Return is not created for the Stock Picking"
return01.is_return_stock_picking,
"Return is not created for the Stock Picking",
)
return01.is_refund = True
self.assertTrue(return01.is_refund, "You cannot create refund")
Expand Down
3 changes: 1 addition & 2 deletions bad_connector_woocommerce/views/sale_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@
<field name="woo_bind_ids" invisible="1" />
<field name="is_final_status" invisible="1" />
<field name="woo_order_status_code" invisible="1" />
<field name="is_fully_returned" invisible="1" />
<button
name="export_delivery_status"
type="object"
Expand All @@ -82,7 +81,7 @@
/>
<field name="tax_different" invisible="1" />
<field name="total_amount_different" invisible="1" />
<field name="is_fully_returned" invisible="1" />
<field name="is_fully_returned" />
</xpath>
<xpath
expr="//form/sheet/group/group/field[@name='payment_term_id']"
Expand Down
3 changes: 2 additions & 1 deletion bad_connector_woocommerce/views/stock_picking.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
<xpath expr="//sheet/group/group/field[@name='origin']" position="after">
<field name="woo_bind_ids" invisible="1" />
<field name="sale_woo_binding_ids" invisible="1" />
<field name="is_return_stock_picking" invisible="1" />
<field
name="is_refund"
attrs="{'invisible':['|','|','|',('is_return_picking','=',False),('state','not in','done'),('woo_bind_ids', '!=', []),('sale_woo_binding_ids','=',[])]}"
attrs="{'invisible':['|','|','|',('is_return_stock_picking','=',False),('state','not in','done'),('woo_bind_ids', '!=', []),('sale_woo_binding_ids','=',[])]}"
/>
</xpath>
<xpath expr="//notebook" position="inside">
Expand Down

0 comments on commit e38d018

Please sign in to comment.