mirror of
https://github.com/ForgeFlow/stock-rma.git
synced 2025-01-21 12:57:49 +02:00
IMP: added case for receipt policy with prepaid invoice required
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
"wizard/wizard_create_invoice_rma_view.xml",
|
||||
"views/account_move_view.xml",
|
||||
"views/rma_order_line_view.xml",
|
||||
"views/rma_operation_view.xml",
|
||||
],
|
||||
"maintainers": ["ChisOForgeFlow"],
|
||||
"development_status": "Beta",
|
||||
|
||||
@@ -7,12 +7,17 @@ class RmaOperation(models.Model):
|
||||
|
||||
_inherit = "rma.operation"
|
||||
|
||||
invoice_policy = fields.Selection(
|
||||
string="Invoice policy",
|
||||
selection=[
|
||||
("no", "Can't Create Services Invoice"),
|
||||
("yes", "Can Create Services Invoice"),
|
||||
receipt_policy = fields.Selection(
|
||||
selection_add=[
|
||||
("prepaid_invoice_ordered", "Prepaid Service Invoice - Ordered"),
|
||||
("prepaid_invoice_delivered", "Prepaid Service Invoice - Delivered"),
|
||||
],
|
||||
required=False,
|
||||
default="no",
|
||||
ondelete={
|
||||
"prepaid_invoice_ordered": lambda recs: recs.write(
|
||||
{"receipt_policy": "ordered"}
|
||||
),
|
||||
"prepaid_invoice_delivered": lambda recs: recs.write(
|
||||
{"receipt_policy": "delivered"}
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
@@ -8,12 +8,19 @@ class RmaOrderLine(models.Model):
|
||||
|
||||
_inherit = "rma.order.line"
|
||||
|
||||
invoice_policy = fields.Selection(
|
||||
string="Invoice policy",
|
||||
selection=[
|
||||
("no", "No Service Invoice"),
|
||||
("yes", "Create Service Invoice"),
|
||||
receipt_policy = fields.Selection(
|
||||
selection_add=[
|
||||
("prepaid_invoice_ordered", "Prepaid Service Invoice - Ordered"),
|
||||
("prepaid_invoice_delivered", "Prepaid Service Invoice - Delivered"),
|
||||
],
|
||||
ondelete={
|
||||
"prepaid_invoice_ordered": lambda recs: recs.write(
|
||||
{"receipt_policy": "ordered"}
|
||||
),
|
||||
"prepaid_invoice_delivered": lambda recs: recs.write(
|
||||
{"receipt_policy": "delivered"}
|
||||
),
|
||||
},
|
||||
)
|
||||
|
||||
invoice_ids = fields.Many2many(comodel_name="account.move", string="Invoices")
|
||||
@@ -56,21 +63,37 @@ class RmaOrderLine(models.Model):
|
||||
action["domain"] = action["domain"]
|
||||
return action
|
||||
|
||||
def _prepare_rma_line_from_stock_move(self, sm, lot=False):
|
||||
operation_model = self.env["rma.operation"]
|
||||
res = super()._prepare_rma_line_from_stock_move(sm, lot)
|
||||
if res.get("operation_id", False):
|
||||
operation = operation_model.browse(res.get("operation_id", False))
|
||||
res.update(
|
||||
{
|
||||
"invoice_policy": operation.invoice_policy,
|
||||
}
|
||||
)
|
||||
return res
|
||||
qty_to_receive = fields.Float(
|
||||
compute="_compute_qty_to_receive",
|
||||
store=True,
|
||||
)
|
||||
|
||||
@api.onchange("operation_id")
|
||||
def _onchange_operation_id(self):
|
||||
res = super()._onchange_operation_id()
|
||||
if self.operation_id:
|
||||
self.invoice_policy = self.operation_id.invoice_policy
|
||||
return res
|
||||
@api.depends(
|
||||
"move_ids",
|
||||
"move_ids.state",
|
||||
"qty_received",
|
||||
"receipt_policy",
|
||||
"product_qty",
|
||||
"type",
|
||||
"invoice_ids.payment_state",
|
||||
)
|
||||
def _compute_qty_to_receive(self):
|
||||
for rec in self:
|
||||
qty_to_receive = 0.0
|
||||
if rec.receipt_policy == "ordered":
|
||||
qty_to_receive = rec.product_qty - rec.qty_received
|
||||
elif rec.receipt_policy == "delivered":
|
||||
qty_to_receive = rec.qty_delivered - rec.qty_received
|
||||
elif rec.receipt_policy in (
|
||||
"prepaid_invoice_ordered",
|
||||
"prepaid_invoice_delivered",
|
||||
):
|
||||
not_paid_invoices = rec.invoice_ids.filtered(
|
||||
lambda x: x.payment_state not in ("paid", "in_payment")
|
||||
)
|
||||
if not (not rec.invoice_ids or not_paid_invoices):
|
||||
if rec.receipt_policy == "prepaid_invoice_ordered":
|
||||
qty_to_receive = rec.product_qty - rec.qty_received
|
||||
if rec.receipt_policy == "prepaid_invoice_delivered":
|
||||
qty_to_receive = rec.qty_delivered - rec.qty_received
|
||||
rec.qty_to_receive = qty_to_receive
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
<data>
|
||||
|
||||
<record id="rma_operation_form" model="ir.ui.view">
|
||||
<field name="name">rma.operation.form.view</field>
|
||||
<field name="model">rma.operation</field>
|
||||
<field name="inherit_id" ref="rma.rma_operation_form" />
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='delivery_policy']" position="after">
|
||||
<field name="invoice_policy" />
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</data>
|
||||
</odoo>
|
||||
@@ -23,16 +23,20 @@
|
||||
/>
|
||||
</button>
|
||||
</xpath>
|
||||
<xpath expr="//field[@name='receipt_policy']" position="before">
|
||||
<field name="invoice_policy" />
|
||||
</xpath>
|
||||
<xpath expr="//button[@name='action_rma_done']" position="after">
|
||||
<field name="invoice_ids" widget="many2many_tags" invisible="1" />
|
||||
<button
|
||||
name="%(wizard_create_invoice_rma_action)d"
|
||||
type="action"
|
||||
string="Create Services Invoice"
|
||||
attrs="{'invisible': ['|', '|', ('receipt_policy', 'in', ('prepaid_invoice_ordered', 'prepaid_invoice_delivered')), ('state', '=', 'draft'), ('invoice_ids', '!=', [])]}"
|
||||
/>
|
||||
<button
|
||||
name="%(wizard_create_invoice_rma_action)d"
|
||||
type="action"
|
||||
string="Create Services Invoice"
|
||||
class="oe_highlight"
|
||||
attrs="{'invisible': ['|', ('invoice_policy', '!=', 'yes'), ('state', '=', 'draft')]}"
|
||||
attrs="{'invisible': ['|', '|', ('receipt_policy', 'not in', ('prepaid_invoice_ordered', 'prepaid_invoice_delivered')), ('state', '=', 'draft'), ('invoice_ids', '!=', [])]}"
|
||||
/>
|
||||
</xpath>
|
||||
</field>
|
||||
|
||||
Reference in New Issue
Block a user