Skip to content

Commit

Permalink
[FIX] misc. issues with purchase_ext_sst (#79)
Browse files Browse the repository at this point in the history
* move update_lock from purchase.order to res.partner

* shorten variables

* fix issue of not being able to update PO when tentative_name is blank, remove unnecessary product_tmpl_id ref

* misc. fixes
  • Loading branch information
yostashiro authored and AungKoKoLin1997 committed Oct 25, 2023
1 parent 36a2d0b commit 3101fa1
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 35 deletions.
3 changes: 2 additions & 1 deletion purchase_ext_sst/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
'name': 'Extension for purchase functions',
'version': '11.0.1.8.0',
'author': 'Quartile Limited',
'website': 'https://www.odoo-asia.com',
'website': 'https://www.quartile.co',
'category': 'Purchase',
'license': "AGPL-3",
'description': "",
Expand All @@ -19,6 +19,7 @@
'data/purchase_category_data.xml',
'views/request_channel_views.xml',
'views/request_medium_views.xml',
'views/res_partner_views.xml',
'views/purchase_category_views.xml',
'views/purchase_order_views.xml',
'views/hr_employee_views.xml',
Expand Down
1 change: 1 addition & 0 deletions purchase_ext_sst/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-

from . import res_partner
from . import request_channel
from . import request_medium
from . import purchase_category
Expand Down
58 changes: 27 additions & 31 deletions purchase_ext_sst/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

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


class PurchaseOrder(models.Model):
Expand Down Expand Up @@ -31,10 +32,7 @@ class PurchaseOrder(models.Model):
'8.5', '9.0', '9.5', '10.0']],
string='Worked Hours',
)
supplier_update_lock = fields.Boolean(
'Supplier Update Lock',
default=False,
)


@api.onchange('purchased_by_id')
def onchange_purchased_by_id(self):
Expand Down Expand Up @@ -87,39 +85,34 @@ def open_record(self):
@api.multi
def write(self, vals):
res = super(PurchaseOrder, self).write(vals)
for purchase_order in self:
if not purchase_order.supplier_update_lock:
if 'phone' in vals and vals['phone'] and \
self.is_default_partner(self.partner_id.id):
purchase_order.partner_id = self.get_purchase_order_partner(
vals)
if not self.is_default_partner(self.partner_id.id) and \
purchase_order.tentative_name != '未確認':
purchase_order.partner_id.name = \
purchase_order.tentative_name
for order_line in purchase_order.order_line:
product = order_line.product_id.product_tmpl_id
if product.shop_id != purchase_order.shop_id:
product.shop_id = purchase_order.shop_id
if product.purchased_by_id != purchase_order.purchased_by_id:
product.purchased_by_id = purchase_order.purchased_by_id
for order in self:
if 'phone' in vals and vals['phone']:
if self.is_default_partner(self.partner_id.id):
order.partner_id = self.get_partner(vals)
elif order.phone and order.tentative_name and \
order.tentative_name != '未確認':
#FIXME this check should be handled in res.partner
if not order.partner_id.update_lock:
order.partner_id.name = order.tentative_name
else:
raise UserError(_(
'Name of this partner cannot be updated.'))
for line in order.order_line:
product = line.product_id
if product.shop_id != order.shop_id:
product.shop_id = order.shop_id
if product.purchased_by_id != order.purchased_by_id:
product.purchased_by_id = order.purchased_by_id
return res

@api.model
def create(self, vals):
if not ('supplier_update_lock' in vals and vals[
'supplier_update_lock']):
if 'phone' in vals and vals['phone'] and self.is_default_partner(
vals['partner_id']):
vals['partner_id'] = self.get_purchase_order_partner(vals)
if not self.is_default_partner(vals['partner_id']) and \
'tentative_name' in vals and \
vals['tentative_name'] != '未確認':
self.env['res.partner'].browse(vals['partner_id']).name = vals[
'tentative_name']
if 'phone' in vals and vals['phone'] and self.is_default_partner(
vals['partner_id']):
vals['partner_id'] = self.get_partner(vals)
return super(PurchaseOrder, self).create(vals)

def get_purchase_order_partner(self, vals):
def get_partner(self, vals):
phone = vals['phone'] if 'phone' in vals else False
partners = False
if phone:
Expand All @@ -131,6 +124,9 @@ def get_purchase_order_partner(self, vals):
if not partners:
if 'tentative_name' in vals and vals['tentative_name']:
name = vals['tentative_name']
# in case tentative name had already been saved without phone
elif self.tentative_name:
name = self.tentative_name
else:
name = '未確認'
new_partner = self.env['res.partner'].create({
Expand Down
15 changes: 15 additions & 0 deletions purchase_ext_sst/models/res_partner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# -*- coding: utf-8 -*-
# Copyright 2018 Quartile Limited
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models, fields


class Partner(models.Model):
_inherit = "res.partner"

update_lock = fields.Boolean(
'Update Lock',
help="If selected, the partner will not be updated through purchase "
"order creation/update.",
)
3 changes: 0 additions & 3 deletions purchase_ext_sst/views/purchase_order_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@
<xpath expr="//notebook/page[2]//field[@name='date_planned']" position="attributes">
<attribute name="required">False</attribute>
</xpath>
<xpath expr="//field[@name='date_order']" position="after">
<field name="supplier_update_lock" groups="base.group_system"/>
</xpath>
</field>
</record>

Expand Down
15 changes: 15 additions & 0 deletions purchase_ext_sst/views/res_partner_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>

<record id="view_partner_form" model="ir.ui.view">
<field name="name">view.partner.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='type']" position="after">
<field name="update_lock" groups="base.group_system"/>
</xpath>
</field>
</record>

</odoo>

0 comments on commit 3101fa1

Please sign in to comment.