Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
aa.gusti
/
odoo-dev
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit b2869fc2
authored
Nov 29, 2021
by
aa.gusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
penambahan wp_id pada product
1 parent
e2f7cd02
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
147 additions
and
77 deletions
pdl_kab/models/product.py
pdl_kab/report/hide_default_report.xml
pdl_kab/views/product.xml
pdl_kab/models/product.py
View file @
b2869fc
import
base64
import
base64
import
io
import
io
import
logging
import
os
import
os
from
random
import
randrange
from
random
import
randrange
from
PIL
import
Image
from
odoo
import
models
,
fields
,
api
,
tools
,
_
from
odoo
import
models
,
fields
,
api
,
tools
,
_
from
odoo.exceptions
import
UserError
,
ValidationError
from
odoo.exceptions
import
UserError
from
odoo.modules
import
get_resource_path
from
odoo.modules
import
get_resource_path
from
PIL
import
Image
import
logging
_logger
=
logging
.
getLogger
(
__name__
)
_logger
=
logging
.
getLogger
(
__name__
)
TYPE_LIST
=
[(
'hotel'
,
'Hotel'
),
TYPE_LIST
=
[(
'hotel'
,
'Hotel'
),
...
@@ -43,11 +41,23 @@ class Product(models.Model):
...
@@ -43,11 +41,23 @@ class Product(models.Model):
'abt'
:
'set default'
,
'abt'
:
'set default'
,
'parkir'
:
'set default'
'parkir'
:
'set default'
})
})
partner_id
=
fields
.
Many2one
(
'res.partner'
,
string
=
"Partner Related"
)
# wp_name = fields.Many2one(
def
_get_logo
(
self
):
# 'res.partner', compute='_compute_wp', inverse='_inverse_wp_name',
return
base64
.
b64encode
(
# string="Nama")
open
(
os
.
path
.
join
(
tools
.
config
[
'root_path'
],
'addons'
,
'base'
,
'static'
,
'img'
,
'res_company_logo.png'
),
'rb'
)
.
read
())
logo
=
fields
.
Binary
(
related
=
'partner_id.image_1920'
,
default
=
_get_logo
,
string
=
"Product Logo"
,
readonly
=
False
)
# logo_web: do not store in attachments, since the image is retrieved in SQL for
# performance reasons (see addons/web/controllers/main.py, Binary.product_logo)
logo_web
=
fields
.
Binary
(
compute
=
'_compute_logo_web'
,
store
=
True
,
attachment
=
False
)
# currency_id = fields.Many2one('res.currency', string='Currency', required=True,
# default=lambda self: self._default_currency_id())
# user_ids = fields.Many2many('res.users', 'res_product_users_rel', 'cid', 'user_id', string='Accepted Users')
# Objek Pajak as Partner
partner_id
=
fields
.
Many2one
(
'res.partner'
,
string
=
"Objek Pajak"
)
district_id
=
fields
.
Many2one
(
district_id
=
fields
.
Many2one
(
'res.district'
,
compute
=
'_compute_address'
,
inverse
=
'_inverse_district'
,
'res.district'
,
compute
=
'_compute_address'
,
inverse
=
'_inverse_district'
,
string
=
"Kab/Kota"
,
domain
=
"[('state_id', '=?', state_id)]"
,
string
=
"Kab/Kota"
,
domain
=
"[('state_id', '=?', state_id)]"
,
...
@@ -62,15 +72,41 @@ class Product(models.Model):
...
@@ -62,15 +72,41 @@ class Product(models.Model):
'res.district.village'
,
compute
=
'_compute_address'
,
inverse
=
'_inverse_village'
,
'res.district.village'
,
compute
=
'_compute_address'
,
inverse
=
'_inverse_village'
,
string
=
"Desa/Kelurahan"
,
domain
=
"[('sub_district_id', '=?', sub_district_id)]"
string
=
"Desa/Kelurahan"
,
domain
=
"[('sub_district_id', '=?', sub_district_id)]"
)
)
company_id
=
fields
.
Many2one
(
'res.company'
,
related
=
'partner_id.company_id'
,
company_id
=
fields
.
Many2one
(
string
=
'Lembaga/Organisasi'
,
required
=
True
,
'res.company'
,
related
=
'partner_id.company_id'
,
string
=
'Lembaga/Organisasi'
,
store
=
True
,
readonly
=
False
,
default
=
lambda
self
:
self
.
env
.
company
.
id
if
not
self
.
company_id
else
False
,
default
=
lambda
self
:
self
.
env
.
company
.
id
required
=
False
,
store
=
True
,
readonly
=
False
,
if
not
self
.
company_id
else
False
)
)
street
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_street'
)
wp_id
=
fields
.
Many2one
(
street2
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_street2'
)
'res.partner'
,
compute
=
'_compute_wp'
,
inverse
=
'_inverse_wp_id'
,
zip
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_zip'
)
string
=
"Wajib Pajak"
,
store
=
False
)
city
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_city'
)
state_id
=
fields
.
Many2one
(
'res.country.state'
,
compute
=
'_compute_address'
,
inverse
=
'_inverse_state'
,
string
=
"Fed. State"
,
domain
=
"[('country_id', '=?', country_id)]"
)
country_id
=
fields
.
Many2one
(
'res.country'
,
compute
=
'_compute_address'
,
inverse
=
'_inverse_country'
,
string
=
"Country"
)
email
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_email'
)
phone
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_phone'
)
website
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_website'
)
vat
=
fields
.
Char
(
related
=
'partner_id.vat'
,
string
=
"Tax ID"
,
readonly
=
False
)
@tools.ormcache
()
def
_get_default_category_id
(
self
):
# Deletion forbidden (at least through unlink)
return
self
.
env
.
ref
(
'pdl_kab.pc_hotel'
)
categ_id
=
fields
.
Many2one
(
'product.category'
,
'Product Category'
,
change_default
=
True
,
default
=
_get_default_category_id
,
group_expand
=
'_read_group_categ_id'
,
required
=
True
,
help
=
"Select category for the current product"
,
domain
=
"[('type', '=?', type)]"
,
)
# Wajib Pajak (Partner Parent dari Partner OP)
wp_id
=
fields
.
Many2one
(
'res.partner'
,
string
=
"Wajib Pajak"
)
wp_name
=
fields
.
Char
(
related
=
'wp_id.name'
,
string
=
"Wajib Pajak"
,
store
=
True
)
wp_street
=
fields
.
Char
(
compute
=
'_compute_wp'
,
store
=
False
)
wp_street
=
fields
.
Char
(
compute
=
'_compute_wp'
,
store
=
False
)
wp_street2
=
fields
.
Char
(
compute
=
'_compute_wp'
,
store
=
False
)
wp_street2
=
fields
.
Char
(
compute
=
'_compute_wp'
,
store
=
False
)
wp_village_id
=
fields
.
Many2one
(
'res.district.village'
,
compute
=
'_compute_wp'
,
store
=
False
)
wp_village_id
=
fields
.
Many2one
(
'res.district.village'
,
compute
=
'_compute_wp'
,
store
=
False
)
...
@@ -78,14 +114,15 @@ class Product(models.Model):
...
@@ -78,14 +114,15 @@ class Product(models.Model):
wp_district_id
=
fields
.
Many2one
(
'res.district'
,
compute
=
'_compute_wp'
,
store
=
False
)
wp_district_id
=
fields
.
Many2one
(
'res.district'
,
compute
=
'_compute_wp'
,
store
=
False
)
wp_state_id
=
fields
.
Many2one
(
'res.country.state'
,
compute
=
'_compute_wp'
,
store
=
False
)
wp_state_id
=
fields
.
Many2one
(
'res.country.state'
,
compute
=
'_compute_wp'
,
store
=
False
)
wp_zip
=
fields
.
Char
(
compute
=
'_compute_wp'
,
string
=
"ZIP"
)
wp_zip
=
fields
.
Char
(
compute
=
'_compute_wp'
,
string
=
"ZIP"
)
wp_phone
=
fields
.
Char
(
compute
=
'_compute_wp'
,
string
=
"Phone"
)
wp_phone
=
fields
.
Char
(
compute
=
'_compute_wp'
,
string
=
"Phone"
)
wp_email
=
fields
.
Char
(
compute
=
'_compute_wp'
,
string
=
"Email"
)
wp_email
=
fields
.
Char
(
compute
=
'_compute_wp'
,
string
=
"Email"
)
wp_website
=
fields
.
Char
(
compute
=
'_compute_wp'
,
string
=
"Web Site"
)
wp_website
=
fields
.
Char
(
compute
=
'_compute_wp'
,
string
=
"Web Site"
)
rate
=
fields
.
Float
(
related
=
'categ_id.rate'
,
store
=
True
,
readonly
=
False
)
rate
=
fields
.
Float
(
related
=
'categ_id.rate'
,
store
=
True
,
readonly
=
False
)
# Prosesing Wajib Pajak
def
_get_wp_address_field_names
(
self
):
def
_get_wp_address_field_names
(
self
):
return
[
return
[
(
"wp_id"
,
"id"
),
#
("wp_id", "id"),
(
"wp_street"
,
"street"
),
(
"wp_street"
,
"street"
),
(
"wp_street2"
,
"street2"
),
(
"wp_street2"
,
"street2"
),
(
"wp_village_id"
,
"village_id"
),
(
"wp_village_id"
,
"village_id"
),
...
@@ -108,15 +145,16 @@ class Product(models.Model):
...
@@ -108,15 +145,16 @@ class Product(models.Model):
return
field
return
field
def
_compute_wp
(
self
):
def
_compute_wp
(
self
):
for
wp
in
self
.
filtered
(
lambda
product
:
product
.
partner_id
):
if
self
.
wp_id
:
if
not
wp
.
partner_id
:
for
product
in
self
.
filtered
(
lambda
product
:
product
.
wp_id
):
continue
address_data
=
product
.
wp_id
.
sudo
()
.
address_get
(
adr_pref
=
[
'wp'
])
address_data
=
wp
.
partner_id
.
parent_id
.
sudo
()
.
address_get
(
adr_pref
=
[
'wp'
])
if
address_data
[
'wp'
]:
if
address_data
[
'wp'
]:
partner
=
product
.
partner_id
.
browse
(
address_data
[
'wp'
])
.
sudo
()
partner
=
wp
.
partner_id
.
browse
(
address_data
[
'wp'
])
.
sudo
()
product
.
update
(
product
.
_get_wp_address_update
(
partner
))
wp
.
update
(
wp
.
_get_wp_address_update
(
partner
))
else
:
else
:
product
.
update
(
product
.
_get_wp_address_update
(
False
))
wp
.
update
(
wp
.
_get_wp_address_update
(
False
))
else
:
self
.
update
(
self
.
_get_wp_address_update
(
False
))
@api.onchange
(
'wp_id'
)
@api.onchange
(
'wp_id'
)
def
_onchange_wp_id
(
self
):
def
_onchange_wp_id
(
self
):
...
@@ -132,12 +170,7 @@ class Product(models.Model):
...
@@ -132,12 +170,7 @@ class Product(models.Model):
self
.
wp_website
=
self
.
wp_id
.
website
self
.
wp_website
=
self
.
wp_id
.
website
def
copy
(
self
,
default
=
None
):
def
copy
(
self
,
default
=
None
):
raise
UserError
(
_
(
'Duplicating a company is not allowed. Please create a new company instead.'
))
raise
UserError
(
_
(
'Duplicating a object pajak is not allowed. Please create a new object pajak instead.'
))
def
_get_logo
(
self
):
return
base64
.
b64encode
(
open
(
os
.
path
.
join
(
tools
.
config
[
'root_path'
],
'addons'
,
'base'
,
'static'
,
'img'
,
'res_company_logo.png'
),
'rb'
)
.
read
())
def
_get_default_favicon
(
self
,
original
=
False
):
def
_get_default_favicon
(
self
,
original
=
False
):
img_path
=
get_resource_path
(
'web'
,
'static/src/img/favicon.ico'
)
img_path
=
get_resource_path
(
'web'
,
'static/src/img/favicon.ico'
)
...
@@ -165,44 +198,6 @@ class Product(models.Model):
...
@@ -165,44 +198,6 @@ class Product(models.Model):
new_image
.
save
(
stream
,
format
=
"ICO"
)
new_image
.
save
(
stream
,
format
=
"ICO"
)
return
base64
.
b64encode
(
stream
.
getvalue
())
return
base64
.
b64encode
(
stream
.
getvalue
())
@tools.ormcache
()
def
_get_default_category_id
(
self
):
# Deletion forbidden (at least through unlink)
return
self
.
env
.
ref
(
'product.product_category_all'
)
@tools.ormcache
()
def
_get_default_category_id
(
self
):
# Deletion forbidden (at least through unlink)
return
self
.
env
.
ref
(
'pdl_kab.pc_hotel'
)
logo
=
fields
.
Binary
(
related
=
'partner_id.image_1920'
,
default
=
_get_logo
,
string
=
"Company Logo"
,
readonly
=
False
)
# logo_web: do not store in attachments, since the image is retrieved in SQL for
# performance reasons (see addons/web/controllers/main.py, Binary.product_logo)
logo_web
=
fields
.
Binary
(
compute
=
'_compute_logo_web'
,
store
=
True
,
attachment
=
False
)
# currency_id = fields.Many2one('res.currency', string='Currency', required=True,
# default=lambda self: self._default_currency_id())
# user_ids = fields.Many2many('res.users', 'res_product_users_rel', 'cid', 'user_id', string='Accepted Users')
street
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_street'
)
street2
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_street2'
)
zip
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_zip'
)
city
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_city'
)
state_id
=
fields
.
Many2one
(
'res.country.state'
,
compute
=
'_compute_address'
,
inverse
=
'_inverse_state'
,
string
=
"Fed. State"
,
domain
=
"[('country_id', '=?', country_id)]"
)
country_id
=
fields
.
Many2one
(
'res.country'
,
compute
=
'_compute_address'
,
inverse
=
'_inverse_country'
,
string
=
"Country"
)
email
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_email'
)
phone
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_phone'
)
website
=
fields
.
Char
(
compute
=
'_compute_address'
,
inverse
=
'_inverse_website'
)
vat
=
fields
.
Char
(
related
=
'partner_id.vat'
,
string
=
"Tax ID"
,
readonly
=
False
)
categ_id
=
fields
.
Many2one
(
'product.category'
,
'Product Category'
,
change_default
=
True
,
default
=
_get_default_category_id
,
group_expand
=
'_read_group_categ_id'
,
required
=
True
,
help
=
"Select category for the current product"
,
domain
=
"[('type', '=?', type)]"
,
)
# Inversing Wajib Pajak
# Inversing Wajib Pajak
def
_inverse_wp_id
(
self
):
def
_inverse_wp_id
(
self
):
for
product
in
self
:
for
product
in
self
:
...
...
pdl_kab/report/hide_default_report.xml
0 → 100644
View file @
b2869fc
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record
id=
"report_product_label"
model=
"ir.actions.report"
>
<field
name=
"name"
>
Product Label (PDF)
</field>
<field
name=
"model"
>
product.product
</field>
<field
name=
"report_type"
>
qweb-pdf
</field>
<field
name=
"report_name"
>
product.report_productlabel
</field>
<field
name=
"report_file"
>
product.report_productlabel
</field>
<field
name=
"print_report_name"
>
'Products Labels - %s' % (object.name)
</field>
<field
name=
"binding_model_id"
ref=
"product.model_product_product"
/>
<field
name=
"binding_type"
>
report
</field>
<field
name=
"menu"
>
False
</field>
</record>
<record
id=
"report_product_template_label"
model=
"ir.actions.report"
>
<field
name=
"name"
>
Product Label (PDF)
</field>
<field
name=
"model"
>
product.template
</field>
<field
name=
"report_type"
>
qweb-pdf
</field>
<field
name=
"report_name"
>
product.report_producttemplatelabel
</field>
<field
name=
"report_file"
>
product.report_producttemplatelabel
</field>
<field
name=
"print_report_name"
>
'Products Labels - %s' % (object.name)
</field>
<field
name=
"binding_model_id"
ref=
"product.model_product_template"
/>
<field
name=
"binding_type"
>
report
</field>
<field
name=
"menu"
>
False
</field>
</record>
<record
id=
"report_product_product_barcode"
model=
"ir.actions.report"
>
<field
name=
"name"
>
Product Barcode (PDF)
</field>
<field
name=
"model"
>
product.product
</field>
<field
name=
"report_type"
>
qweb-pdf
</field>
<field
name=
"report_name"
>
product.report_productbarcode
</field>
<field
name=
"report_file"
>
product.report_productbarcode
</field>
<field
name=
"print_report_name"
>
'Products barcode - %s' % (object.name)
</field>
<field
name=
"binding_model_id"
ref=
"product.model_product_product"
/>
<field
name=
"binding_type"
>
report
</field>
<field
name=
"menu"
>
False
</field>
</record>
<record
id=
"report_product_template_barcode"
model=
"ir.actions.report"
>
<field
name=
"name"
>
Product Barcode (PDF)
</field>
<field
name=
"model"
>
product.template
</field>
<field
name=
"report_type"
>
qweb-pdf
</field>
<field
name=
"report_name"
>
product.report_producttemplatebarcode
</field>
<field
name=
"report_file"
>
product.report_producttemplatebarcode
</field>
<field
name=
"print_report_name"
>
'Products barcode - %s' % (object.name)
</field>
<field
name=
"binding_model_id"
ref=
"product.model_product_template"
/>
<field
name=
"binding_type"
>
report
</field>
<field
name=
"menu"
>
False
</field>
</record>
<record
id=
"report_product_packaging"
model=
"ir.actions.report"
>
<field
name=
"name"
>
Product Packaging (PDF)
</field>
<field
name=
"model"
>
product.packaging
</field>
<field
name=
"report_type"
>
qweb-pdf
</field>
<field
name=
"report_name"
>
product.report_packagingbarcode
</field>
<field
name=
"report_file"
>
product.report_packagingbarcode
</field>
<field
name=
"print_report_name"
>
'Products packaging - %s' % (object.name)
</field>
<field
name=
"binding_model_id"
ref=
"product.model_product_packaging"
/>
<field
name=
"binding_type"
>
report
</field>
<field
name=
"menu"
>
False
</field>
</record>
<record
id=
"action_report_pricelist"
model=
"ir.actions.report"
>
<field
name=
"name"
>
Pricelist
</field>
<field
name=
"model"
>
product.product
</field>
<field
name=
"report_type"
>
qweb-pdf
</field>
<field
name=
"report_name"
>
product.report_pricelist
</field>
<field
name=
"report_file"
>
product.report_pricelist
</field>
<field
name=
"menu"
>
False
</field>
</record>
</data>
</odoo>
pdl_kab/views/product.xml
View file @
b2869fc
...
@@ -11,7 +11,8 @@
...
@@ -11,7 +11,8 @@
<!-- <field name="lst_price" string="Min Omset"/>-->
<!-- <field name="lst_price" string="Min Omset"/>-->
<field
name=
"wp_id"
string=
"Wajib Pajak"
/>
<field
name=
"wp_id"
string=
"Wajib Pajak"
/>
<field
name=
"type"
string=
"Jenis"
/>
<field
name=
"type"
string=
"Jenis"
/>
<field
name=
"company_id"
string=
"Lembaga/Organisasi"
/>
<field
name=
"company_id"
string=
"Lembaga/Organisasi"
groups=
"base.group_multi_company"
/>
</tree>
</tree>
</field>
</field>
</record>
</record>
...
@@ -72,10 +73,10 @@
...
@@ -72,10 +73,10 @@
<field
name=
"wp_id"
string=
"Wajib Pajak"
domain=
"[('type','=', 'wp')]"
<field
name=
"wp_id"
string=
"Wajib Pajak"
domain=
"[('type','=', 'wp')]"
options=
'{"no_open": False}'
options=
'{"no_open": False}'
context=
"{'default_type': 'wp', 'readonly_type':True}"
/>
context=
"{'default_type': 'wp', 'readonly_type':True}"
/>
<!-- <field name="wp_name" class="o_address_street"/>-->
<label
for=
"street"
string=
"Address"
/>
<label
for=
"street"
string=
"Address"
/>
<div
class=
"o_address_format"
>
<div
class=
"o_address_format"
>
<field
name=
"wp_street"
placeholder=
"Street..."
class=
"o_address_street"
<field
name=
"wp_street"
placeholder=
"Street..."
class=
"o_address_street"
/>
readonly=
"1"
required=
"0"
/>
<field
name=
"wp_street2"
placeholder=
"Street 2..."
class=
"o_address_street"
/>
<field
name=
"wp_street2"
placeholder=
"Street 2..."
class=
"o_address_street"
/>
<field
name=
"wp_village_id"
class=
"o_address_city"
placeholder=
"Desa/Keurahan"
<field
name=
"wp_village_id"
class=
"o_address_city"
placeholder=
"Desa/Keurahan"
options=
'{"no_open": True}'
/>
options=
'{"no_open": True}'
/>
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment