Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wip #15

Open
wants to merge 2 commits into
base: 16.0-purchase_update_proposal_group_backend
Choose a base branch
from
Open

wip #15

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions purchase_update_proposal/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
Purchase Update Proposal
========================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:1980276aaf72580b8f7903e0595dcadfc4df2160e9d7633cc31276cfca1d457d
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
Expand All @@ -14,16 +17,16 @@ Purchase Update Proposal
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/purchase-workflow/tree/8.0/purchase_update_proposal
:target: https://github.com/OCA/purchase-workflow/tree/16.0/purchase_update_proposal
:alt: OCA/purchase-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/purchase-workflow-8-0/purchase-workflow-8-0-purchase_update_proposal
:target: https://translation.odoo-community.org/projects/purchase-workflow-16-0/purchase-workflow-16-0-purchase_update_proposal
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/142/8.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=16.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|
|badge1| |badge2| |badge3| |badge4| |badge5|

Allow for any user with only read only grants on Purchase Orders to suggest/ask for modification.

Expand All @@ -49,13 +52,13 @@ Usage
Go to the supplier menu
This document is modified by the supplier with specific right on its own purchase document

.. figure:: https://raw.githubusercontent.com/OCA/purchase-workflow/8.0/purchase_update_proposal/static/description/supplier.png
.. figure:: https://raw.githubusercontent.com/OCA/purchase-workflow/16.0/purchase_update_proposal/static/description/supplier.png



This document is modified by the purchaser pending approbation

.. figure:: https://raw.githubusercontent.com/OCA/purchase-workflow/8.0/purchase_update_proposal/static/description/purchaser.png
.. figure:: https://raw.githubusercontent.com/OCA/purchase-workflow/16.0/purchase_update_proposal/static/description/purchaser.png


Features:
Expand All @@ -72,8 +75,8 @@ Bug Tracker

Bugs are tracked on `GitHub Issues <https://github.com/OCA/purchase-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_update_proposal%0Aversion:%208.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/purchase-workflow/issues/new?body=module:%20purchase_update_proposal%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Expand Down Expand Up @@ -101,11 +104,14 @@ promote its widespread use.
.. |maintainer-bealdav| image:: https://github.com/bealdav.png?size=40px
:target: https://github.com/bealdav
:alt: bealdav
.. |maintainer-FranzPoize| image:: https://github.com/FranzPoize.png?size=40px
:target: https://github.com/FranzPoize
:alt: FranzPoize

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
Current `maintainers <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-bealdav|
|maintainer-bealdav| |maintainer-FranzPoize|

This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/8.0/purchase_update_proposal>`_ project on GitHub.
This module is part of the `OCA/purchase-workflow <https://github.com/OCA/purchase-workflow/tree/16.0/purchase_update_proposal>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
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
93 changes: 23 additions & 70 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,29 @@ 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.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 +87,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,63 +110,24 @@ 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":
# example: qty is in proposal and purchase is partially received
if not self.proposal_updatable:
# example: qty is in proposal and purchase unshipped is lower
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"
)
data = self._prepare_proposal_data()
if data:
self._hook_pending_proposal_approval()
if self._product_qty_key_in_data(data) and self.state in [
"confirmed",
"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()
# clean accepted proposals
self.env["purchase.line.proposal"].search([("order_id", "=", self.id)]).unlink()
self.write({"proposal_state": "approved"})

def _product_qty_key_in_data(self, data):
"""Check if 'product_qty' key is anywhere in data"""
self.ensure_one()
qty2update = False
for __, vals in data.items():
for key in vals:
if "product_qty" in key:
qty2update = qty2update or True
else:
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.
Context can't be used because it disappears in the global odoo process
So you may make changes in your custom process to capture falsy cancellation
"""
return

def _prepare_proposal_data(self):
self.ensure_one()
res = defaultdict(list)
Expand Down Expand Up @@ -247,7 +198,7 @@ def write(self, vals):
and self.proposal_state != "rejected"
):
vals["proposal_display"] = False
return super(PurchaseOrder, self).write(vals)
return super().write(vals)

def _get_purchase_groups(self):
"""Guess if the user is a standard purchaser"""
Expand All @@ -259,11 +210,13 @@ def _get_purchase_groups(self):
]

def _fields_prevent_to_update(self, vals):
"Unauthorised users should only update a strict subset of purchase fields"
if [x for x in vals.keys() if x[:9] != "proposal_"]:
return True
return False

def _subscribe_portal_vendor(self):
"You may call it to submit this document to partners"
self.ensure_one()
cial_partner = self.partner_id.commercial_partner_id
partner_ids = cial_partner.child_ids.ids
Expand All @@ -277,7 +230,7 @@ def _subscribe_portal_vendor(self):
in s.groups_id
)
if users:
self.message_subscribe_users(users.ids)
self.message_subscribe(users.mapped("partner_id").ids)

def button_switch2other_view(self):
self.ensure_one()
Expand Down
24 changes: 1 addition & 23 deletions purchase_update_proposal/models/purchase_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,33 +18,11 @@ class PurchaseOrderLine(models.Model):
compute="_compute_supplier_cancel_status",
help="Indicate if the line is cancelled",
)
received = fields.Selection(
selection=[("", "No"), ("partially", "Partially"), ("all", "All")],
compute="_compute_received",
compute_sudo=True,
store=False,
help="Defined if quantity is partially or "
"completely received (at least the quantity of the line)",
)

def _compute_received(self):
for rec in self:
received = sum(
rec.move_ids.filtered(lambda s: s.state == "done").mapped(
"product_uom_qty"
)
)
if received >= rec.product_qty:
rec.received = "all"
elif not received:
rec.received = ""
else:
rec.received = "partially"

def _compute_supplier_cancel_status(self):
for rec in self:
cancel_status = False
if rec.state == "cancel":
if rec.state == "cancel" or not rec.product_qty:
cancel_status = _("Cancel")
rec.supplier_cancel_status = cancel_status

Expand Down
7 changes: 2 additions & 5 deletions purchase_update_proposal/models/purchase_proposal.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,8 @@ class PurchaseLineProposal(models.Model):
date = fields.Date(
string="New Date", compute="_compute_date", store=True, readonly=False
)
price_u = fields.Float(
string="New Price U.",
digits="Product Price",
)
partially_received = fields.Boolean(related="order_id.partially_received")
price_u = fields.Float(string="New Price U.", digits="Product Price")
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
Loading