Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
bealdav committed Apr 2, 2024
1 parent 6a31aa5 commit ccadb31
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 74 deletions.
2 changes: 1 addition & 1 deletion purchase_update_proposal/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
],
"installable": True,
"development_status": "Alpha",
"maintainers": ["bealdav"],
"maintainers": ["bealdav", "FranzPoize"],
}
12 changes: 0 additions & 12 deletions purchase_update_proposal/i18n/fr.po
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@ msgstr "Annulé"
msgid "Check price on proposal"
msgstr "Vérifier le prix lors de la proposition d'achat"

#. module: purchase_update_proposal
#: help:purchase.line.proposal,partially_received:0
#: help:purchase.order,partially_received:0
msgid "Checked if at least partially delivered"
msgstr "Coché si la ligne est partiellement livré"

#. module: purchase_update_proposal
#: help:purchase.order,proposal_updatable:0
msgid ""
Expand Down Expand Up @@ -248,12 +242,6 @@ msgstr "Mois de commande"
msgid "Partially"
msgstr "Partially"

#. module: purchase_update_proposal
#: field:purchase.line.proposal,partially_received:0
#: field:purchase.order,partially_received:0
msgid "Partially received"
msgstr "Partially received"

#. module: purchase_update_proposal
#: model:ir.model,name:purchase_update_proposal.model_res_partner
msgid "Partner"
Expand Down
12 changes: 0 additions & 12 deletions purchase_update_proposal/i18n/purchase_update_proposal.pot
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ msgstr ""
msgid "Check price on proposal"
msgstr ""

#. module: purchase_update_proposal
#: help:purchase.line.proposal,partially_received:0
#: help:purchase.order,partially_received:0
msgid "Checked if at least partially delivered"
msgstr ""

#. module: purchase_update_proposal
#: help:purchase.order,proposal_updatable:0
msgid "Computed to be sure that stock move are in a state compatible with update"
Expand Down Expand Up @@ -238,12 +232,6 @@ msgstr ""
msgid "Partially"
msgstr ""

#. module: purchase_update_proposal
#: field:purchase.line.proposal,partially_received:0
#: field:purchase.order,partially_received:0
msgid "Partially received"
msgstr ""

#. module: purchase_update_proposal
#: model:ir.model,name:purchase_update_proposal.model_res_partner
msgid "Partner"
Expand Down
58 changes: 20 additions & 38 deletions purchase_update_proposal/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@ class PurchaseOrder(models.Model):
copy=False,
default="draft",
)
proposal_updatable = fields.Selection(
selection=[("", "undefined"), ("yes", "Yes"), ("no", "No")],
default="",
proposal_updatable = fields.Boolean(
default=True,
copy=False,
help="Computed to be sure that stock move are in a state "
"compatible with update",
Expand All @@ -47,38 +46,30 @@ class PurchaseOrder(models.Model):
string="Display/Hide Proposal",
help="If checked, rejected proposals are hidden.",
)
partially_received = fields.Boolean(
compute="_compute_partially_received",
store=False,
compute_sudo=True,
help="Checked if at least partially delivered",
)

def _compute_partially_received(self):
for rec in self:
received = [x.received for x in rec.order_line if x.received]
if received:
rec.partially_received = True
else:
rec.partially_received = False

def _check_updatable_proposal(self):
"""Override original method"""
for rec in self:
prevent_update = False
if rec.partially_received:
for __, vals in rec._prepare_proposal_data().items():
for elm in vals:
if "product_qty" in elm:
if rec.receipt_status == "full":
rec.proposal_updatable = False
elif rec.receipt_status in (False, "pending"):
rec.proposal_updatable = True
elif rec.receipt_status == "partial":
for pol, vals_list in rec._prepare_proposal_data().items():
for vals in vals_list:
if (
"product_qty" in vals
and pol
and (pol.product_qty - pol.qty_received)
< vals["product_qty"]
):
prevent_update = prevent_update or True
else:
prevent_update = prevent_update or False
if prevent_update:
rec.proposal_updatable = "no"
else:
rec.proposal_updatable = "yes"
rec.proposal_updatable = not prevent_update
else:
rec.proposal_updatable = "yes"
rec.proposal_updatable = True

def _compute_proposal(self):
for rec in self:
Expand All @@ -97,7 +88,7 @@ def submit_proposal(self):
self.ensure_one()
self._prepare_proposal_data()
self._check_updatable_proposal()
if self.proposal_updatable == "yes":
if self.proposal_updatable:
self.write({"proposal_state": "submitted"})

def reset_proposal(self):
Expand All @@ -120,11 +111,11 @@ def approve_proposal(self):
if not self._get_purchase_groups():
raise UserError(_("You are not authorized to approve this proposal"))
self._check_updatable_proposal()
if self.proposal_updatable == "no":
if not self.proposal_updatable:
# example: qty is in proposal and purchase is partially received
# TODO : in 16.0 or later we might rise this restriction
return
body = []
initial_state = False
# these proposals'll reset these lines
lines_to_0 = self.proposal_ids.filtered(lambda s: s.qty == 0.0).mapped(
"line_id"
Expand All @@ -137,15 +128,10 @@ def approve_proposal(self):
"approved",
]:
# We have to reset order because of changed qty in confirmed order
initial_state = self.state
self.action_cancel()
self.action_cancel_draft()
self._update_proposal_to_purchase_line(data, body)
self.message_post(body="\n".join(body))
if initial_state in ("approved", "confirmed"):
# altered quantity implied to reset order, then we approve them again
self.signal_workflow("purchase_confirm")
self.signal_workflow("purchase_approve")
# Cancellation cases
if lines_to_0:
lines_to_0.cancel_from_proposal()
Expand All @@ -165,10 +151,6 @@ def _product_qty_key_in_data(self, data):
qty2update = qty2update or False
return qty2update

def _hook_for_cancel_process(self):
"TODO remove: Kept for compatibility"
self._hook_pending_proposal_approval()

def _hook_pending_proposal_approval(self):
"""Cancellation here is a fake one, in fact it's a workaround
to cleanly update purchase when picking has been created.
Expand Down
2 changes: 1 addition & 1 deletion purchase_update_proposal/models/purchase_proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class PurchaseLineProposal(models.Model):
string="New Price U.",
digits="Product Price",
)
partially_received = fields.Boolean(related="order_id.partially_received")
receipt_status = fields.Selection(related="order_id.receipt_status")
check_price = fields.Boolean(related="order_id.partner_id.check_price_on_proposal")

@api.depends("order_id.proposal_date")
Expand Down
2 changes: 1 addition & 1 deletion purchase_update_proposal/tests/test_proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ def test_proposal_workflow(self):
prop = order_s.proposal_ids[0]
prop.write({"qty": 10, "price_u": 2})
order_s.submit_proposal()
assert order_s.proposal_updatable == "yes"
assert order_s.proposal_updatable
assert order.proposal_state == "submitted"
order.approve_proposal()
# We check all is correctly written
Expand Down
12 changes: 10 additions & 2 deletions purchase_update_proposal/tests/test_proposal_with_picking.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ def test_received_field(self):
lambda s: s.product_id == pick.move_ids[0].product_id
)
assert line.received == "partially"
assert order.partially_received is True

def test_date_field(self):
order = self.get_order_with_user(alternate_user=True)
Expand Down Expand Up @@ -84,7 +83,16 @@ def test_qty_field(self):
self.order.approve_proposal()
assert self.other_line.product_qty != 97
assert self.order.proposal_state == "draft"
assert self.order.proposal_updatable == "no"
assert not self.order.proposal_updatable

def test_less_qty(self):
order = self.order
self.lamp_line.button_update_proposal()
order.proposal_ids[0].qty = 20
order._check_updatable_proposal()
assert not order.proposal_updatable
# order.approve_proposal()
# assert self.lamp_line.product_qty == 20

def test_populate_all_lines(self):
order = self.get_order_with_user(alternate_user=True)
Expand Down
4 changes: 2 additions & 2 deletions purchase_update_proposal/views/purchase_line_proposal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<field name="product_id" />
<field
name="qty"
attrs="{'readonly': [('partially_received', '=', True)]}"
attrs="{'readonly': [('receipt_status', '=', 'full')]}"
/>
<field name="date" />
<field
Expand All @@ -24,7 +24,7 @@
<field name="price_unit" />
<field name="line_id" invisible="1" />
<field name="order_id" invisible="1" />
<field name="partially_received" invisible="1" />
<field name="receipt_status" invisible="1" />
<field name="check_price" invisible="1" />
</tree>
</field>
Expand Down
4 changes: 2 additions & 2 deletions purchase_update_proposal/views/purchase_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
name="proposal_ids"
mode="tree"
nolabel="1"
attrs="{'readonly': [('proposal_updatable', '=', 'no')]}"
attrs="{'readonly': [('proposal_updatable', '=', False)]}"
>
<tree>
<field name="line_id_" />
Expand All @@ -97,7 +97,7 @@
<field name="check_price_on_proposal" invisible="1" />
<field name="proposal_updatable" invisible="1" />
<div
attrs="{'invisible': [('proposal_updatable', '!=', 'no')]}"
attrs="{'invisible': [('proposal_updatable', '!=', False)]}"
style="background-color:red; color:white; text-align:center; font-weight: bold;"
>
We can't complete your request because our incoming workflow is partially finished or cancelled
Expand Down
5 changes: 2 additions & 3 deletions purchase_update_proposal/views/supplier_purchase_order.xml
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,6 @@
/>
</group>
<field name="proposal_count" invisible="1" />
<field name="partially_received" invisible="1" />
<div attrs="{'invisible': [('proposal_count', '=', 0)]}">
<div
attrs="{'invisible': [('proposal_state', '!=', 'submitted')]}"
Expand All @@ -189,13 +188,13 @@
</div>
<field
name="proposal_ids"
attrs="{'readonly': [('proposal_updatable', '=', 'no')]}"
attrs="{'readonly': [('proposal_updatable', '=', False)]}"
nolabel="1"
/>
<field name="check_price_on_proposal" invisible="1" />
<field name="proposal_updatable" invisible="1" />
<div
attrs="{'invisible': [('proposal_updatable', '!=', 'no')]}"
attrs="{'invisible': [('proposal_updatable', '!=', False)]}"
style="background-color:red; color:white; text-align:center; font-weight: bold;"
>
We can't complete your request because our incoming workflow is partially finished or cancelled
Expand Down

0 comments on commit ccadb31

Please sign in to comment.