Skip to content

Commit

Permalink
[16.0][MIG] sale_blanket_order: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenminhchien committed Dec 13, 2023
1 parent 4d91759 commit 84b5552
Show file tree
Hide file tree
Showing 16 changed files with 459 additions and 349 deletions.
35 changes: 22 additions & 13 deletions sale_blanket_order/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Sale Blanket Orders
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/sale-workflow/tree/15.0/sale_blanket_order
:target: https://github.com/OCA/sale-workflow/tree/16.0/sale_blanket_order
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-15-0/sale-workflow-15-0-sale_blanket_order
:target: https://translation.odoo-community.org/projects/sale-workflow-16-0/sale-workflow-16-0-sale_blanket_order
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/15.0
:alt: Try me on Runbot
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/webui/builds.html?repo=OCA/sale-workflow&target_branch=16.0
:alt: Try me on Runboat

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

Expand All @@ -42,7 +42,7 @@ A new menu in the Sales area is created, allowing users to create new blanket or

To create a new Sale Blanket Order go to the sale menu in the Sales section:

.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/15.0/sale_blanket_order/static/description/BO_menu.png
.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/16.0/sale_blanket_order/static/description/BO_menu.png
:alt: Blanket Orders menu

Hitting the button create will open the form view in which we can introduce the following
Expand All @@ -58,27 +58,27 @@ information:
* Original, Ordered, Invoiced, Received and Remaining quantities
* Terms and Conditions of the Blanket Order

.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/15.0/sale_blanket_order/static/description/BO_form.png
.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/16.0/sale_blanket_order/static/description/BO_form.png
:alt: Blanket Orders form

From the form, once the Blanket Order has been confirmed and its state is open, the user can
create a Sale Order, check the Sale Orders associated to the Blanket Order and/or
see the Blanket Order lines associated to the BO.

.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/15.0/sale_blanket_order/static/description/BO_actions.png
.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/16.0/sale_blanket_order/static/description/BO_actions.png
:alt: Actions that can be done from Blanket Order

Hitting the button Create Sale Order will open a wizard that will ask for the amount of each
product in the BO lines for which the Sale Order will be created.

.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/15.0/sale_blanket_order/static/description/PO_from_BO.png
.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/16.0/sale_blanket_order/static/description/PO_from_BO.png
:alt: Create Sale Order from Blanket Order

Installing this module will add an additional menu which will show all the blanket order lines
currently defined in the system. From this list the user can create customized Sale Orders
selecting the lines for which the PO (or POs if the customers are different) is (are) created.

.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/15.0/sale_blanket_order/static/description/BO_lines.png
.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/16.0/sale_blanket_order/static/description/BO_lines.png
:alt: Blanket Order lines and actions

In the Sale Order form one field is added in the PO lines, the Blanket Order line field. This
Expand All @@ -89,7 +89,7 @@ factors:
* Closer Validity date
* Remaining quantity > Quantity introduced in the Sale Order line

.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/15.0/sale_blanket_order/static/description/PO_BOLine.png
.. figure:: https://raw.githubusercontent.com/OCA/sale-workflow/16.0/sale_blanket_order/static/description/PO_BOLine.png
:alt: New field added in Sale Order Line

Bug Tracker
Expand All @@ -98,7 +98,7 @@ Bug Tracker
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-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/sale-workflow/issues/new?body=module:%20sale_blanket_order%0Aversion:%2015.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_blanket_order%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 All @@ -117,6 +117,15 @@ Contributors
* Adrià Gil Sorribes <[email protected]> (https://www.eficent.com/)
* Jordi Ballester Alomar <[email protected]>
* Alex Comba <[email protected]> (https://www.agilebg.com/)
* Jasper Jumelet <[email protected]> (https://www.codeforward.nl/)
* `Trobz <https://trobz.com>`_:

* Nguyễn Minh Chiến <[email protected]>

Other credits
~~~~~~~~~~~~~

The migration of this module from 15.0 to 16.0 was financially supported by Camptocamp

Maintainers
~~~~~~~~~~~
Expand All @@ -131,6 +140,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

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

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
3 changes: 2 additions & 1 deletion sale_blanket_order/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"category": "Sale",
"license": "AGPL-3",
"author": "Acsone SA/NV, Odoo Community Association (OCA)",
"version": "15.0.1.2.0",
"version": "16.0.1.0.0",
"website": "https://github.com/OCA/sale-workflow",
"summary": "Blanket Orders",
"depends": ["uom", "sale_management", "web_action_conditionable"],
Expand All @@ -17,6 +17,7 @@
"wizard/create_sale_orders.xml",
"views/sale_config_settings.xml",
"views/sale_blanket_order_views.xml",
"views/sale_blanket_order_line_views.xml",
"views/sale_order_views.xml",
"report/templates.xml",
"report/report.xml",
Expand Down
98 changes: 37 additions & 61 deletions sale_blanket_order/models/blanket_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,14 @@
from odoo.tools import float_is_zero
from odoo.tools.misc import format_date

from odoo.addons.sale.models.sale_order import READONLY_FIELD_STATES


class BlanketOrder(models.Model):
_name = "sale.blanket.order"
_inherit = ["mail.thread", "mail.activity.mixin"]
_description = "Blanket Order"

@api.model
def _get_default_team(self):
return self.env["crm.team"]._get_default_team_id()

@api.model
def _default_currency(self):
return self.env.company.currency_id

@api.model
def _default_company(self):
return self.env.company
_check_company_auto = True

@api.model
def _default_note(self):
Expand Down Expand Up @@ -53,8 +44,7 @@ def _compute_amount_all(self):
partner_id = fields.Many2one(
"res.partner",
string="Partner",
readonly=True,
states={"draft": [("readonly", False)]},
states=READONLY_FIELD_STATES,
)
line_ids = fields.One2many(
"sale.blanket.order.line", "order_id", string="Order lines", copy=True
Expand All @@ -73,24 +63,21 @@ def _compute_amount_all(self):
"product.pricelist",
string="Pricelist",
required=True,
readonly=True,
states={"draft": [("readonly", False)]},
states=READONLY_FIELD_STATES,
)
currency_id = fields.Many2one("res.currency", related="pricelist_id.currency_id")
analytic_account_id = fields.Many2one(
comodel_name="account.analytic.account",
string="Analytic Account",
readonly=True,
copy=False,
check_company=True,
states={"draft": [("readonly", False)]},
states=READONLY_FIELD_STATES,
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
)
payment_term_id = fields.Many2one(
"account.payment.term",
string="Payment Terms",
readonly=True,
states={"draft": [("readonly", False)]},
states=READONLY_FIELD_STATES,
)
confirmed = fields.Boolean(copy=False)
state = fields.Selection(
Expand All @@ -104,36 +91,32 @@ def _compute_amount_all(self):
store=True,
copy=False,
)
validity_date = fields.Date(readonly=True, states={"draft": [("readonly", False)]})
validity_date = fields.Date(
states=READONLY_FIELD_STATES,
)
client_order_ref = fields.Char(
string="Customer Reference",
copy=False,
readonly=True,
states={"draft": [("readonly", False)]},
)
note = fields.Text(
readonly=True, default=_default_note, states={"draft": [("readonly", False)]}
states=READONLY_FIELD_STATES,
)
note = fields.Text(default=_default_note, states=READONLY_FIELD_STATES)
user_id = fields.Many2one(
"res.users",
string="Salesperson",
readonly=True,
states={"draft": [("readonly", False)]},
states=READONLY_FIELD_STATES,
)
team_id = fields.Many2one(
"crm.team",
string="Sales Team",
change_default=True,
default=_get_default_team,
readonly=True,
states={"draft": [("readonly", False)]},
default=lambda self: self.env["crm.team"]._get_default_team_id(),
states=READONLY_FIELD_STATES,
)
company_id = fields.Many2one(
"res.company",
string="Company",
default=_default_company,
readonly=True,
states={"draft": [("readonly", False)]},
comodel_name="res.company",
required=True,
index=True,
default=lambda self: self.env.company,
)
sale_count = fields.Integer(compute="_compute_sale_count")

Expand Down Expand Up @@ -227,11 +210,11 @@ def _compute_state(self):

def _compute_uom_qty(self):
for bo in self:
bo.original_uom_qty = sum(bo.mapped("order_id.original_uom_qty"))
bo.ordered_uom_qty = sum(bo.mapped("order_id.ordered_uom_qty"))
bo.invoiced_uom_qty = sum(bo.mapped("order_id.invoiced_uom_qty"))
bo.delivered_uom_qty = sum(bo.mapped("order_id.delivered_uom_qty"))
bo.remaining_uom_qty = sum(bo.mapped("order_id.remaining_uom_qty"))
bo.original_uom_qty = sum(bo.mapped("line_ids.original_uom_qty"))
bo.ordered_uom_qty = sum(bo.mapped("line_ids.ordered_uom_qty"))
bo.invoiced_uom_qty = sum(bo.mapped("line_ids.invoiced_uom_qty"))
bo.delivered_uom_qty = sum(bo.mapped("line_ids.delivered_uom_qty"))
bo.remaining_uom_qty = sum(bo.mapped("line_ids.remaining_uom_qty"))

@api.onchange("partner_id")
def onchange_partner_id(self):
Expand Down Expand Up @@ -259,7 +242,7 @@ def onchange_partner_id(self):
),
"fiscal_position_id": self.env["account.fiscal.position"]
.with_context(company_id=self.company_id.id)
.get_fiscal_position(self.partner_id.id),
._get_fiscal_position(self.partner_id),
}

if self.partner_id.user_id:
Expand Down Expand Up @@ -331,7 +314,7 @@ def action_cancel(self):

def action_view_sale_orders(self):
sale_orders = self._get_sale_orders()
action = self.env.ref("sale.action_orders").read()[0]
action = self.env["ir.actions.act_window"]._for_xml_id("sale.action_orders")
if len(sale_orders) > 0:
action["domain"] = [("id", "in", sale_orders.ids)]
action["context"] = [("id", "in", sale_orders.ids)]
Expand All @@ -340,9 +323,9 @@ def action_view_sale_orders(self):
return action

def action_view_sale_blanket_order_line(self):
action = self.env.ref(
"sale_blanket_order" ".act_open_sale_blanket_order_lines_view_tree"
).read()[0]
action = self.env["ir.actions.act_window"]._for_xml_id(
"sale_blanket_order.act_open_sale_blanket_order_lines_view_tree"
)
lines = self.mapped("line_ids")
if len(lines) > 0:
action["domain"] = [("id", "in", lines.ids)]
Expand All @@ -355,7 +338,7 @@ def expire_orders(self):
[("state", "=", "open"), ("validity_date", "<=", today)]
)
expired_orders.modified(["validity_date"])
expired_orders.recompute()
expired_orders.flush_recordset()

@api.model
def _search_original_uom_qty(self, operator, value):
Expand Down Expand Up @@ -406,7 +389,7 @@ def _search_remaining_uom_qty(self, operator, value):
class BlanketOrderLine(models.Model):
_name = "sale.blanket.order.line"
_description = "Blanket Order Line"
_inherit = ["mail.thread", "mail.activity.mixin"]
_inherit = ["mail.thread", "mail.activity.mixin", "analytic.mixin"]

@api.depends(
"original_uom_qty",
Expand Down Expand Up @@ -453,9 +436,7 @@ def _compute_amount(self):
)
date_schedule = fields.Date(string="Scheduled Date")
original_uom_qty = fields.Float(
string="Original quantity",
default=1,
digits="Product Unit of Measure",
string="Original quantity", default=1, digits="Product Unit of Measure"
)
ordered_uom_qty = fields.Float(
string="Ordered quantity", compute="_compute_quantities", store=True
Expand All @@ -482,7 +463,7 @@ def _compute_amount(self):
copy=False,
)
company_id = fields.Many2one(
"res.company", related="order_id.company_id", store=True
related="order_id.company_id", store=True, index=True, precompute=True
)
currency_id = fields.Many2one("res.currency", related="order_id.currency_id")
partner_id = fields.Many2one(related="order_id.partner_id", string="Customer")
Expand All @@ -497,11 +478,6 @@ def _compute_amount(self):
)
price_total = fields.Monetary(compute="_compute_amount", string="Total", store=True)
price_tax = fields.Float(compute="_compute_amount", string="Tax", store=True)
analytic_tag_ids = fields.Many2many(
comodel_name="account.analytic.tag",
string="Analytic Tags",
domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]",
)
display_type = fields.Selection(
[("line_section", "Section"), ("line_note", "Note")],
default=False,
Expand Down Expand Up @@ -549,7 +525,7 @@ def _get_real_price_currency(self, product, rule_id, qty, uom, pricelist_id):
):
price, rule_id = pricelist_item.base_pricelist_id.with_context(
uom=uom.id
).get_product_price_rule(product, qty, self.order_id.partner_id)
)._get_product_price_rule(product, qty, uom)
pricelist_item = PricelistItem.browse(rule_id)

if pricelist_item.base == "standard_price":
Expand Down Expand Up @@ -593,9 +569,9 @@ def _get_display_price(self, product):
pricelist = self.order_id.pricelist_id
partner = self.order_id.partner_id
if self.order_id.pricelist_id.discount_policy == "with_discount":
return product.with_context(pricelist=pricelist.id).price
final_price, rule_id = pricelist.get_product_price_rule(
self.product_id, self.original_uom_qty or 1.0, partner
return product.with_context(pricelist=pricelist.id).lst_price
final_price, rule_id = pricelist._get_product_price_rule(
self.product_id, self.original_uom_qty or 1.0, self.product_uom
)
context_partner = dict(
self.env.context, partner_id=partner.id, date=fields.Date.today()
Expand Down
Loading

0 comments on commit 84b5552

Please sign in to comment.