Skip to content

Commit

Permalink
Merge PR #4 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by andhit-r
  • Loading branch information
ssi-bot committed Nov 16, 2023
2 parents abd3768 + dfdcaf2 commit a52303b
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ssi_rma/menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
id="menu_rma"
name="RMA"
parent="stock.menu_stock_root"
sequence="20"
sequence="110"
/>
<menuitem
id="menu_rma_config"
Expand Down
55 changes: 54 additions & 1 deletion ssi_rma/models/rma_line_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ class RMALineMixin(models.AbstractModel):
ondelete="cascade",
)
sequence = fields.Integer(string="Sequence", required=True, default=10)
allowed_lot_ids = fields.Many2many(
string="Allowed Lots",
comodel_name="stock.production.lot",
compute="_compute_allowed_lot_ids",
store=False,
)
lot_id = fields.Many2one(comodel_name="stock.production.lot", string="Lot")
stock_move_ids = fields.Many2many(
comodel_name="stock.move",
Expand Down Expand Up @@ -55,6 +61,21 @@ class RMALineMixin(models.AbstractModel):
string="Qty Delivered", compute="_compute_qty_delivered", store=True
)

@api.depends(
"product_id",
)
def _compute_allowed_lot_ids(self):
for record in self:
result = []
if record.product_id:
Lot = self.env["stock.production.lot"]
result = Lot.search(
[
("product_id", "=", record.product_id.id),
]
).ids
record.allowed_lot_ids = result

@api.depends(
"stock_move_ids",
"stock_move_ids.state",
Expand Down Expand Up @@ -137,6 +158,31 @@ def _compute_qty_delivered(self):
]
record.qty_delivered = record._get_rma_move_qty(states, "out")

@api.onchange(
"product_id",
)
def onchange_lot_id(self):
self.lot_id = False

@api.onchange(
"product_id",
"uom_quantity",
"uom_id",
"pricelist_id",
"lot_id",
)
def onchange_price_unit(self):
_super = super(RMALineMixin, self)
self.price_unit = 0.0
if self.lot_id and self.uom_quantity and self.uom_quantity != 0.0:
self.price_unit = 7.0
if self.lot_id.quant_ids:

quant = self.lot_id.quant_ids[-1]
self.price_unit = quant.value / self.uom_quantity
else:
_super.onchange_price_unit()

def _get_rma_move_qty(self, states, direction):
result = 0.0
rma_location = self.order_id.route_template_id.location_id
Expand Down Expand Up @@ -222,6 +268,8 @@ def _get_receipt_procurement_data(self):
"product_uom": self.uom_id.id,
"location_id": location,
"route_ids": route,
"price_unit": self.price_unit,
"forced_lot_id": self.lot_id and self.lot_id.id,
}
if self._name == "rma_customer_line":
result.update(
Expand All @@ -242,6 +290,10 @@ def _get_delivery_procurement_data(self):
origin = self.order_id.name
warehouse = self.order_id.route_template_id.outbound_warehouse_id
route = self.order_id.route_template_id.outbound_route_id
location = (
self.order_id.route_template_id.partner_location_id
or self.order_id.partner_id.property_stock_customer,
) # TODO
result = {
"name": self.order_id.name,
"group_id": group,
Expand All @@ -252,8 +304,9 @@ def _get_delivery_procurement_data(self):
"product_qty": self.qty_to_deliver,
"partner_id": self.order_id.partner_id.id,
"product_uom": self.uom_id.id,
"location_id": self.order_id.partner_id.property_stock_customer,
"location_id": location,
"route_ids": route,
"forced_lot_id": self.lot_id and self.lot_id.id,
}
if self._name == "rma_customer_line":
result.update(
Expand Down
1 change: 1 addition & 0 deletions ssi_rma/models/rma_mixin.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ class RMAMixin(models.AbstractModel):
comodel_name="procurement.group",
string="Procurement Group",
ondelete="restrict",
readonly=True,
)
line_ids = fields.One2many(
comodel_name="rma_line_mixin",
Expand Down
6 changes: 6 additions & 0 deletions ssi_rma/models/rma_route_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class RMARouteTemplate(models.Model):
required=True,
ondelete="restrict",
)
partner_location_id = fields.Many2one(
comodel_name="stock.location",
string="Partner Location",
required=False,
ondelete="restrict",
)
customer_to_supplier = fields.Boolean(
string="The customer will send to the supplier", default=False
)
Expand Down
6 changes: 4 additions & 2 deletions ssi_rma/models/stock_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class StockRule(models.Model):
def _get_custom_move_fields(self):
_super = super(StockRule, self)
result = _super._get_custom_move_fields()
result.append(
result += [
"customer_rma_line_ids",
)
"price_unit",
"forced_lot_id",
]
return result
11 changes: 10 additions & 1 deletion ssi_rma/views/rma_mixin_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@
<field name="sequence" />
<field name="product_id" />
<field name="name" />
<field name="lot_id" />
<field
name="allowed_lot_ids"
widget="many2many_tags"
invisible="1"
/>
<field
name="lot_id"
domain="[('id','in',allowed_lot_ids)]"
/>
</group>
<group name="form_detail2" colspan="1" col="2">
<field
Expand Down Expand Up @@ -153,6 +161,7 @@
class="oe_highlight"
icon="fa-sign-in"
attrs="{'invisible':[('receipt_ok','=',False)]}"
style="margin-right:4px"
/>
<button
name="action_create_delivery"
Expand Down
1 change: 1 addition & 0 deletions ssi_rma/views/rma_route_template_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<data>
<xpath expr="//field[@name='active']" position="after">
<field name="location_id" />
<field name="partner_location_id" />
<field name="customer_to_supplier" />
<field name="supplier_to_customer" />
</xpath>
Expand Down

0 comments on commit a52303b

Please sign in to comment.