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

[15.0][3917][IMP] purchase_order_supplier_phone: add functionals from sst #94

Merged
merged 1 commit into from
Jan 29, 2024
Merged
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
11 changes: 5 additions & 6 deletions purchase_order_supplier_phone/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ Add supplier phone and mobile in purchase
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-qrtl%2Frmm--custom-lightgray.png?logo=github
:target: https://github.com/qrtl/rmm-custom/tree/15.0/purchase_order_supplier_phone
:alt: qrtl/rmm-custom

|badge1| |badge2| |badge3|

This module adds supplier's phone and mobile fields to purchase.order,
add this fields in purchase order tree view and also add this fields in
search view of purchase order.
This module adds the information of supplier in purchase and update
supplier's information when update values in purchase order.

**Table of contents**

Expand Down
8 changes: 5 additions & 3 deletions purchase_order_supplier_phone/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
# Copyright 2022 Quartile Limited
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Add supplier phone and mobile in purchase",
"version": "15.0.1.0.0",
"author": "Quartile Limited",
"website": "https://www.quartile.co",
"category": "Purchase",
"license": "LGPL-3",
"depends": ["purchase"],
"license": "AGPL-3",
"depends": [
"purchase_ext_sst", # is_default_partner()
],
"data": [
"views/purchase_order_views.xml",
],
Expand Down
52 changes: 49 additions & 3 deletions purchase_order_supplier_phone/i18n/ja.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,78 @@ msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 15.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-09-14 06:17+0000\n"
"PO-Revision-Date: 2022-09-14 06:17+0000\n"
"POT-Creation-Date: 2024-01-23 06:43+0000\n"
"PO-Revision-Date: 2024-01-23 06:43+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: purchase_order_supplier_phone
#: code:addons/purchase_order_supplier_phone/models/purchase_order.py:0
#: code:addons/purchase_order_supplier_phone/models/purchase_order.py:0
#, python-format
msgid ""
"\n"
"%(partner_name)s\n"
"- Phone: %(phone)s\n"
"- Mobile: %(mobile)s\n"
msgstr ""

#. module: purchase_order_supplier_phone
#: model:ir.model.fields,field_description:purchase_order_supplier_phone.field_purchase_order__supplier_mobile
msgid "Mobile"
msgstr "携帯電話"

#. module: purchase_order_supplier_phone
#: model:ir.model.fields,field_description:purchase_order_supplier_phone.field_purchase_order__mobile_update
msgid "Mobile Update"
msgstr "携帯電話(更新用)"

#. module: purchase_order_supplier_phone
#: model:ir.model.fields,field_description:purchase_order_supplier_phone.field_purchase_order__supplier_phone
msgid "Phone"
msgstr "電話"

#. module: purchase_order_supplier_phone
#: model:ir.model.fields,field_description:purchase_order_supplier_phone.field_purchase_order__phone_search
msgid "Phone Search"
msgstr "電話(検索用)"

#. module: purchase_order_supplier_phone
#: model:ir.model.fields,field_description:purchase_order_supplier_phone.field_purchase_order__phone_update
msgid "Phone Update"
msgstr "電話(更新用)"

#. module: purchase_order_supplier_phone
#: model:ir.model,name:purchase_order_supplier_phone.model_purchase_order
msgid "Purchase Order"
msgstr "購買オーダ"

#. module: purchase_order_supplier_phone
#: model_terms:ir.ui.view,arch_db:purchase_order_supplier_phone.purchase_order_form_inherit
msgid "Supplier Name Update (Tentative Name)"
msgstr "名称更新(仮称)"

#. module: purchase_order_supplier_phone
#: model_terms:ir.ui.view,arch_db:purchase_order_supplier_phone.purchase_order_view_search
#: model_terms:ir.ui.view,arch_db:purchase_order_supplier_phone.view_purchase_order_filter
#: model_terms:ir.ui.view,arch_db:purchase_order_supplier_phone.view_purchase_order_view_search
msgid "Supplier Phone/Mobile"
msgstr "電話/携帯電話(仕入先)"

#. module: purchase_order_supplier_phone
#: model:ir.model.fields,field_description:purchase_order_supplier_phone.field_purchase_order__tentative_name
msgid "Tentative Name"
msgstr "仮称"

#. module: purchase_order_supplier_phone
#: code:addons/purchase_order_supplier_phone/models/purchase_order.py:0
#: code:addons/purchase_order_supplier_phone/models/purchase_order.py:0
#, python-format
msgid ""
"The entered phone (%(phone)s) conflicts with the following user(s):\n"
"%(conflict_users)s"
msgstr "入力した電話(%s)につきコンフリクトがあります。下記のレコードを確認ください。"
"%(conflict_users)s"
170 changes: 168 additions & 2 deletions purchase_order_supplier_phone/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,185 @@
# Copyright 2022 Quartile Limited
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models
import logging

from odoo import _, api, fields, models
from odoo.exceptions import UserError


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

phone_update = fields.Char()
mobile_update = fields.Char()
phone_search = fields.Char(
states={
"purchase": [("readonly", True)],
"done": [("readonly", True)],
"cancel": [("readonly", True)],
},
)
supplier_phone = fields.Char(
related="partner_id.phone",
string="Supplier Phone",
readonly=True,
store=True,
)
supplier_mobile = fields.Char(
related="partner_id.mobile",
string="Supplier Mobile",
readonly=True,
store=True,
)
tentative_name = fields.Char()

def write(self, vals):
# Propose supplier logic
if (
"phone_search" in vals
or "phone_update" in vals
or "mobile_update" in vals
or "tentative_name" in vals
):
val_phone_search = "phone_search" in vals and vals["phone_search"] or False
val_phone = "phone_update" in vals and vals["phone_update"] or False
val_mobile = "mobile_update" in vals and vals["mobile_update"] or False
for order in self:
val_tent_name = (
"tentative_name" in vals
and vals["tentative_name"]
or order.tentative_name
)
partner_id = (
"partner_id" in vals and vals["partner_id"] or order.partner_id.id
)
if self.is_default_partner(partner_id) and (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_default_partner depends on purchase_ext_sst module.

val_phone or val_mobile or val_phone_search
):
partner_id = self.create_partner(
val_phone or val_phone_search, val_mobile
).id
if not self.is_default_partner(partner_id):
partner = self.env["res.partner"].browse(partner_id)
self.update_partner(partner, val_phone, val_mobile, val_tent_name)
vals["partner_id"] = partner_id
vals["phone_update"] = vals["mobile_update"] = False
return super(PurchaseOrder, self).write(vals)

@api.model
def create(self, vals):
val_phone_search = "phone_search" in vals and vals["phone_search"] or False
val_phone = "phone_update" in vals and vals["phone_update"] or False
val_mobile = "mobile_update" in vals and vals["mobile_update"] or False
val_tent_name = "tentative_name" in vals and vals["tentative_name"] or False
logging.info(self.is_default_partner(vals["partner_id"]))
if self.is_default_partner(vals["partner_id"]) and (
val_phone or val_mobile or val_phone_search
):
vals["partner_id"] = self.create_partner(
val_phone or val_phone_search, val_mobile
).id
if not self.is_default_partner(vals["partner_id"]):
partner = self.env["res.partner"].browse(vals["partner_id"])
self.update_partner(partner, val_phone, val_mobile, val_tent_name)
vals["phone_update"] = vals["mobile_update"] = False
return super(PurchaseOrder, self).create(vals)

def create_partner(self, phone, mobile):
partner = self.env["res.partner"].create(
{
"name": "未確認",
"phone": phone,
"mobile": mobile,
"supplier_rank": 1,
"customer_rank": 0,
}
)
return partner

def update_partner(self, partner, phone, mobile, tent_name):
if phone and partner.phone != phone:
partner.phone = phone
if mobile and partner.mobile != mobile:
partner.mobile = mobile
if tent_name and partner.name != tent_name:
partner.name = tent_name

@api.onchange("phone_search")
def onchange_phone_search(self):
if self.phone_search:
self.phone_update = False
self.mobile_update = False
partner = self.get_partner_from_phone(self.phone_search)
if partner:
self.partner_id = partner
elif self.partner_id:
if self.is_default_partner(self.partner_id.id):
self.phone_update = self.phone_search

@api.onchange("phone_update")
def onchange_phone_update(self):
if self.phone_update:
return self.check_onchange_phone(self.phone_update, "phone_update")

@api.onchange("mobile_update")
def onchange_mobile_update(self):
if self.mobile_update:
return self.check_onchange_phone(self.mobile_update, "mobile_update")

def check_onchange_phone(self, phone, field):
try:
partner = self.get_partner_from_phone(phone)
if self.partner_id and partner and partner != self.partner_id:
conflicts_user = _(
"\n%(partner_name)s\n- Phone: %(phone)s\n- Mobile: %(mobile)s\n"
) % {
"partner_name": partner.name,
"phone": partner.phone or "",
"mobile": partner.mobile or "",
}
return {
"warning": {
"message": _(
"The entered phone (%(phone)s) conflicts with the following"
" user(s):\n%(conflict_users)s"
)
% {"phone": phone or "N/A", "conflict_users": conflicts_user}
},
"value": {field: False},
}
except UserError as e:
return {"warning": {"message": e.name}, "value": {field: False}}

def get_partner_from_phone(self, phone):
Partner = self.env["res.partner"]
partners = False
# here we use "or" condition instead of "and"
if phone:
partners = Partner.search(
[
"|",
("phone", "=", phone),
("mobile", "=", phone),
("active", "=", True),
("supplier_rank", ">", 0),
]
)
if partners and len(partners) > 1:
conflicts_users_list = ""
for partner in partners:
conflicts_users_list += _(
"\n%(partner_name)s\n- Phone: %(phone)s\n- Mobile: %(mobile)s\n"
) % {
"partner_name": partner.name,
"phone": partner.phone or "",
"mobile": partner.mobile or "",
}
raise UserError(
_(
"The entered phone (%(phone)s) conflicts with"
" the following user(s):\n%(conflict_users)s"
)
% {"phone": phone or "N/A", "conflict_users": conflicts_users_list}
)
return partners if partners else False
4 changes: 1 addition & 3 deletions purchase_order_supplier_phone/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
This module adds supplier's phone and mobile fields to purchase.order,
add this fields in purchase order tree view and also add this fields in
search view of purchase order.
This module adds the information of supplier in purchase and update supplier's information when update values in purchase order.
7 changes: 3 additions & 4 deletions purchase_order_supplier_phone/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,9 @@ <h1 class="title">Add supplier phone and mobile in purchase</h1>
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:8b247aeb4bddfe2f848b89fa3d3e7de3684ee2b1ec605a5e833258b0c3aadc1b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/lgpl-3.0-standalone.html"><img alt="License: LGPL-3" src="https://img.shields.io/badge/licence-LGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/qrtl/rmm-custom/tree/15.0/purchase_order_supplier_phone"><img alt="qrtl/rmm-custom" src="https://img.shields.io/badge/github-qrtl%2Frmm--custom-lightgray.png?logo=github" /></a></p>
<p>This module adds supplier’s phone and mobile fields to purchase.order,
add this fields in purchase order tree view and also add this fields in
search view of purchase order.</p>
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/qrtl/rmm-custom/tree/15.0/purchase_order_supplier_phone"><img alt="qrtl/rmm-custom" src="https://img.shields.io/badge/github-qrtl%2Frmm--custom-lightgray.png?logo=github" /></a></p>
<p>This module adds the information of supplier in purchase and update
supplier’s information when update values in purchase order.</p>
<p><strong>Table of contents</strong></p>
<div class="contents local topic" id="contents">
<ul class="simple">
Expand Down
Loading
Loading