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 02d68539
authored
Dec 04, 2022
by
aagusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
price history penambahan graphic dan pivot
1 parent
7faf58b9
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
157 additions
and
51 deletions
id_gov/models/district.py
tandur/models/price_hist.py
tandur/views/menus.xml
tandur/views/price_hist.xml
id_gov/models/district.py
View file @
02d6853
...
...
@@ -8,24 +8,28 @@ _logger = logging.getLogger(__name__)
def
get_selection_label
(
self
,
obj
,
field_name
,
field_value
):
return
dict
(
self
.
env
[
obj
]
.
fields_get
(
allfields
=
[
field_name
])[
field_name
][
'selection'
])[
field_value
]
return
dict
(
self
.
env
[
obj
]
.
fields_get
(
allfields
=
[
field_name
])[
field_name
][
'selection'
])[
field_value
]
class
CountryState
(
models
.
Model
):
_inherit
=
'res.country.state'
district_ids
=
fields
.
One2many
(
'res.district'
,
'state_id'
,
string
=
'Kota/Kabupaten'
)
district_ids
=
fields
.
One2many
(
'res.district'
,
'state_id'
,
string
=
'Kota/Kabupaten'
)
def
name_get
(
self
):
result
=
[]
for
record
in
self
:
result
.
append
((
record
.
id
,
"{} ({})"
.
format
(
record
.
name
,
record
.
code
)))
result
.
append
(
(
record
.
id
,
"{} ({})"
.
format
(
record
.
name
,
record
.
code
)))
return
result
class
District
(
models
.
Model
):
_name
=
'res.district'
_description
=
'Kota/Kabupaten'
state_id
=
fields
.
Many2one
(
'res.country.state'
,
string
=
'Provinsi'
,
required
=
True
)
state_id
=
fields
.
Many2one
(
'res.country.state'
,
string
=
'Provinsi'
,
required
=
True
)
typ
=
fields
.
Selection
([
(
'kab'
,
'Kabupaten'
),
(
'kabtif'
,
'Kabupaten Administratif'
),
...
...
@@ -36,7 +40,8 @@ class District(models.Model):
name
=
fields
.
Char
(
string
=
"Nama Kota/Kabupaten"
,
index
=
True
,
required
=
True
)
# display_code = fields.Char(compute='_compute_display_code', store=True, index=True)
# display_name = fields.Char(compute='_compute_display_name', store=True, index=True)
sub_district_ids
=
fields
.
One2many
(
'res.district.sub'
,
'district_id'
,
string
=
'Kecamatan'
)
sub_district_ids
=
fields
.
One2many
(
'res.district.sub'
,
'district_id'
,
string
=
'Kecamatan'
)
# address_view_id = fields.Many2one(
# comodel_name='ir.ui.view', string="Input View",
# domain=[('model', '=', 'res.partner'), ('type', '=', 'form')],
...
...
@@ -50,15 +55,19 @@ class District(models.Model):
# help="Url of static flag image",
# )
_sql_constraints
=
[
(
'code_uniq'
,
'unique (state_id,code)'
,
'Kode Kabupaten/Kota Harus Unik !'
),
(
'name_uniq'
,
'unique (state_id,typ,name)'
,
'Nama Kabupaten/Kota Harus Unik !'
),
(
'code_uniq'
,
'unique (state_id,code)'
,
'Kode Kabupaten/Kota Harus Unik !'
),
(
'name_uniq'
,
'unique (state_id,typ,name)'
,
'Nama Kabupaten/Kota Harus Unik !'
),
]
@api.model
def
_name_search
(
self
,
name
,
args
=
None
,
operator
=
'ilike'
,
limit
=
100
,
name_get_uid
=
None
):
def
_name_search
(
self
,
name
,
args
=
None
,
operator
=
'ilike'
,
limit
=
100
,
name_get_uid
=
None
):
args
=
args
or
[]
if
self
.
env
.
context
.
get
(
'state_id'
):
args
=
expression
.
AND
([
args
,
[(
'state_id'
,
'='
,
self
.
env
.
context
.
get
(
'state_id'
))]])
args
=
expression
.
AND
(
[
args
,
[(
'state_id'
,
'='
,
self
.
env
.
context
.
get
(
'state_id'
))]])
if
operator
==
'ilike'
and
not
(
name
or
''
)
.
strip
():
first_domain
=
[]
...
...
@@ -67,12 +76,14 @@ class District(models.Model):
first_domain
=
[(
'code'
,
'=ilike'
,
name
)]
domain
=
[(
'name'
,
operator
,
name
)]
first_district_ids
=
self
.
_search
(
expression
.
AND
([
first_domain
,
args
]),
limit
=
limit
,
first_district_ids
=
self
.
_search
(
expression
.
AND
([
first_domain
,
args
]),
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
if
first_domain
else
[]
first_ids
=
list
(
first_district_ids
)
+
[
district_id
for
district_id
in
self
.
_search
(
expression
.
AND
([
domain
,
args
]),
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
if
district_id
not
in
first_district_ids
]
# _logger.info(self.env.context.get('country_id'))
...
...
@@ -92,14 +103,15 @@ class District(models.Model):
result
=
[]
for
record
in
self
:
result
.
append
((
record
.
id
,
"{} {} ({}.{})"
.
format
(
get_selection_label
(
self
,
self
.
_name
,
'typ'
,
record
.
typ
),
record
.
name
,
record
.
state_id
.
code
,
record
.
code
)))
get_selection_label
(
self
,
self
.
_name
,
'typ'
,
record
.
typ
),
record
.
name
,
record
.
state_id
.
code
,
record
.
code
)))
return
result
def
code_get
(
self
):
result
=
[]
for
record
in
self
:
result
.
append
((
record
.
id
,
"{}.{}"
.
format
(
record
.
state_id
.
code
,
record
.
code
)))
result
.
append
(
(
record
.
id
,
"{}.{}"
.
format
(
record
.
state_id
.
code
,
record
.
code
)))
return
result
# @api.model_create_multi
...
...
@@ -131,19 +143,24 @@ class District(models.Model):
class
SubDistrict
(
models
.
Model
):
_name
=
'res.district.sub'
_description
=
'Kecamatan'
district_id
=
fields
.
Many2one
(
'res.district'
,
string
=
'Kabupaten/Kota'
,
required
=
True
)
district_id
=
fields
.
Many2one
(
'res.district'
,
string
=
'Kabupaten/Kota'
,
required
=
True
)
code
=
fields
.
Char
(
string
=
"Kode Kecamatan"
)
name
=
fields
.
Char
(
string
=
"Nama Kecamatan"
,
index
=
True
)
_sql_constraints
=
[
(
'code_uniq'
,
'unique (district_id,code)'
,
'Kode Kecamatan Harus Unik !'
),
(
'name_uniq'
,
'unique (district_id,name)'
,
'Nama Kecamatan Harus Unik !'
),
(
'code_uniq'
,
'unique (district_id,code)'
,
'Kode Kecamatan Harus Unik !'
),
(
'name_uniq'
,
'unique (district_id,name)'
,
'Nama Kecamatan Harus Unik !'
),
]
@api.model
def
_name_search
(
self
,
name
,
args
=
None
,
operator
=
'ilike'
,
limit
=
100
,
name_get_uid
=
None
):
def
_name_search
(
self
,
name
,
args
=
None
,
operator
=
'ilike'
,
limit
=
100
,
name_get_uid
=
None
):
args
=
args
or
[]
if
self
.
env
.
context
.
get
(
'district_id'
):
args
=
expression
.
AND
([
args
,
[(
'district_id'
,
'='
,
self
.
env
.
context
.
get
(
'district_id'
))]])
args
=
expression
.
AND
([
args
,
[
(
'district_id'
,
'='
,
self
.
env
.
context
.
get
(
'district_id'
))]])
if
operator
==
'ilike'
and
not
(
name
or
''
)
.
strip
():
first_domain
=
[]
...
...
@@ -152,12 +169,14 @@ class SubDistrict(models.Model):
first_domain
=
[(
'code'
,
'=ilike'
,
name
)]
domain
=
[(
'name'
,
operator
,
name
)]
first_sub_district_ids
=
self
.
_search
(
expression
.
AND
([
first_domain
,
args
]),
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
if
first_domain
else
[]
first_sub_district_ids
=
self
.
_search
(
expression
.
AND
([
first_domain
,
args
]),
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
if
first_domain
else
[]
return
list
(
first_sub_district_ids
)
+
[
district_id
for
district_id
in
self
.
_search
(
expression
.
AND
([
domain
,
args
]),
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
if
district_id
not
in
first_sub_district_ids
]
...
...
@@ -191,15 +210,20 @@ class Village(models.Model):
name
=
fields
.
Char
(
string
=
"Nama Desa/Kelurahan"
,
index
=
True
)
zip
=
fields
.
Char
(
string
=
"Kode Pos Desa/Kelurahan"
,
size
=
5
,
)
_sql_constraints
=
[
(
'village_code_uniq'
,
'unique (sub_district_id,code)'
,
'Kode Kelurahan/Desa Harus Unik !'
),
(
'village_name_uniq'
,
'unique (sub_district_id,typ,name)'
,
'Nama Kelurahan/Desa Harus Unik !'
),
(
'village_code_uniq'
,
'unique (sub_district_id,code)'
,
'Kode Kelurahan/Desa Harus Unik !'
),
(
'village_name_uniq'
,
'unique (sub_district_id,typ,name)'
,
'Nama Kelurahan/Desa Harus Unik !'
),
]
@api.model
def
_name_search
(
self
,
name
,
args
=
None
,
operator
=
'ilike'
,
limit
=
100
,
name_get_uid
=
None
):
def
_name_search
(
self
,
name
,
args
=
None
,
operator
=
'ilike'
,
limit
=
100
,
name_get_uid
=
None
):
args
=
args
or
[]
if
self
.
env
.
context
.
get
(
'sub_district_id'
):
args
=
expression
.
AND
([
args
,
[(
'sub_district_id'
,
'='
,
self
.
env
.
context
.
get
(
'sub_district_id'
))]])
args
=
expression
.
AND
([
args
,
[(
'sub_district_id'
,
'='
,
self
.
env
.
context
.
get
(
'sub_district_id'
))]])
# _logger.info(self.env.context.get('sub_district_id'))
# _logger.info(args)
...
...
@@ -210,12 +234,14 @@ class Village(models.Model):
first_domain
=
[(
'code'
,
'=ilike'
,
name
)]
domain
=
[(
'name'
,
operator
,
name
)]
first_village_ids
=
self
.
_search
(
expression
.
AND
([
first_domain
,
args
]),
limit
=
limit
,
first_village_ids
=
self
.
_search
(
expression
.
AND
([
first_domain
,
args
]),
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
if
first_domain
else
[]
first_ids
=
list
(
first_village_ids
)
+
[
sub_district_id
for
sub_district_id
in
self
.
_search
(
expression
.
AND
([
domain
,
args
]),
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
limit
=
limit
,
access_rights_uid
=
name_get_uid
)
if
sub_district_id
not
in
first_village_ids
]
# _logger.info(first_ids)
...
...
@@ -235,7 +261,8 @@ class Village(models.Model):
result
=
[]
for
record
in
self
:
result
.
append
((
record
.
id
,
"{} {} ({}.{}.{}.{})"
.
format
(
get_selection_label
(
self
,
self
.
_name
,
'typ'
,
record
.
typ
),
record
.
name
,
get_selection_label
(
self
,
self
.
_name
,
'typ'
,
record
.
typ
),
record
.
name
,
record
.
sub_district_id
.
district_id
.
state_id
.
code
,
record
.
sub_district_id
.
district_id
.
code
,
record
.
sub_district_id
.
code
,
record
.
code
)))
...
...
tandur/models/price_hist.py
View file @
02d6853
...
...
@@ -18,11 +18,20 @@ class TandurPriceHist(models.Model):
_name
=
'tandur.price.hist'
_description
=
'History of Price'
_order
=
"product_id"
@api.depends
(
'year'
,
'month'
)
def
_compute_period
(
self
):
for
record
in
self
:
self
.
period
=
"{}-{}"
.
format
(
str
(
int
(
record
.
year
)),
str
(
int
(
record
.
month
))
.
zfill
(
2
))
year
=
fields
.
Float
(
string
=
'Year'
,
group_operator
=
False
)
month
=
fields
.
Float
(
string
=
'Month'
,
group_operator
=
False
)
product_id
=
fields
.
Many2one
(
'product.product'
,
'Product'
,
required
=
True
)
price
=
fields
.
Float
(
string
=
'Price'
,
group_operator
=
False
)
period
=
fields
.
Char
(
compute
=
'_compute_period'
,
store
=
True
,
index
=
True
)
product_id
=
fields
.
Many2one
(
'product.product'
,
'Product'
,
required
=
True
)
price
=
fields
.
Float
(
string
=
'Price'
,
group_operator
=
"avg"
)
@api.model
def
fields_view_get
(
self
,
view_id
=
None
,
view_type
=
'form'
,
toolbar
=
False
,
submenu
=
False
):
...
...
@@ -41,3 +50,11 @@ class TandurPriceHist(models.Model):
# res['arch'] = ElementTree.tostring(root)
#
# return res
def
name_get
(
self
):
result
=
[]
for
record
in
self
:
result
.
append
(
(
record
.
id
,
"{}-{}"
.
format
(
str
(
int
(
record
.
year
)),
str
(
int
(
record
.
month
))
.
zfill
(
2
))))
return
result
tandur/views/menus.xml
View file @
02d6853
...
...
@@ -175,7 +175,7 @@
<menuitem
id=
"tandur_price_menu"
name=
"Price History"
parent=
"tandur_config_menu"
action=
"
tandur_price_hist_action
"
action=
"
action_tandur_price_hist
"
sequence=
"2"
/>
<data>
...
...
tandur/views/price_hist.xml
View file @
02d6853
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record
id=
"tandur_price_hist_view_tree"
model=
"ir.ui.view"
>
<record
id=
"view_tandur_price_hist_tree"
model=
"ir.ui.view"
>
<field
name=
"name"
>
view.tandur.price.hist.tree
</field>
<field
name=
"model"
>
tandur.price.hist
</field>
<field
name=
"arch"
type=
"xml"
>
<tree
string=
"Price History"
editable=
"top"
sample=
"1"
create=
"1"
delete=
"1"
multi_edit=
"0
"
>
<
field
name=
"year"
/
>
<field
name=
"
month
"
/>
<tree
string=
"Price History"
sample=
"1"
create=
"1"
delete=
"1
"
>
<
!-- editable="top" --
>
<field
name=
"
period
"
/>
<field
name=
"product_id"
/>
<field
name=
"price"
/>
</tree>
</field>
</record>
<!--editable="top" sample="1" create="1" delete="1" multi_edit="0"-->
<!-- <record id="view_tandur_price_hist_tree" model="ir.ui.view">-->
<!-- <field name="name">view.tandur.price.hist.tree</field>-->
<!-- <field name="model">tandur.price.hist</field>-->
<!-- <field name="arch" type="xml">-->
<!-- <tree string="Price History" editable="top" sample="1" multi_edit="0">-->
<!-- <field name="year"/>-->
<!-- <field name="month"/>-->
<!-- <field name="period"/>-->
<!-- <field name="product_id"/>-->
<!-- <field name="price"/>-->
<!-- </tree>-->
<!-- </field>-->
<!-- </record>-->
<record
id=
"view_tandur_price_hist_form"
model=
"ir.ui.view"
>
<field
name=
"name"
>
view.tandur.price.hist.form
</field>
<field
name=
"model"
>
tandur.price.hist
</field>
<field
name=
"arch"
type=
"xml"
>
<form
string=
"Price History"
>
<sheet>
<div
class=
"oe_title"
>
<h1>
<field
name=
"product_id"
/>
</h1>
</div>
<group>
<field
name=
"year"
options=
"{'format': 0}"
/>
<field
name=
"month"
options=
"{'format': 00}"
/>
<field
name=
"price"
/>
</group>
</sheet>
</form>
</field>
</record>
<record
model=
"ir.ui.view"
id=
"tandur_price_hist_graph"
>
<field
name=
"name"
>
tandur.price.hist.graph
</field>
<field
name=
"model"
>
tandur.price.hist
</field>
<field
name=
"arch"
type=
"xml"
>
<graph
string=
"Price History"
sample=
"1"
>
<field
name=
"period"
/>
<field
name=
"product_id"
/>
<field
name=
"price"
type=
"measure"
/>
</graph>
</field>
</record>
<record
model=
"ir.ui.view"
id=
"tandur_price_hist_pivot"
>
<field
name=
"name"
>
tandur.price.hist.pivot
</field>
<field
name=
"model"
>
tandur.price.hist
</field>
<field
name=
"arch"
type=
"xml"
>
<pivot
string=
"Price History"
display_quantity=
"True"
sample=
"1"
>
<field
name=
"product_id"
type=
"row"
/>
<field
name=
"period"
type=
"row"
/>
<field
name=
"price"
type=
"measure"
/>
</pivot>
</field>
</record>
<record
id=
"view_tandur_price_hist_filter"
model=
"ir.ui.view"
>
<field
name=
"name"
>
tandur.price.hist.select
</field>
<field
name=
"name"
>
view.tandur.price.hist.filter
</field>
<field
name=
"model"
>
tandur.price.hist
</field>
<field
name=
"arch"
type=
"xml"
>
<search
string=
"Search Product"
>
<field
name=
"product_id"
string=
"Product"
/>
<separator/>
<group
expand=
"0"
string=
"Group By..."
>
<filter
string=
"Product"
name=
"group_by_product"
domain=
"[]"
context=
"{'group_by': 'product_id'}"
/>
<filter
string=
"Product"
name=
"group_by_product"
domain=
"[]"
context=
"{'group_by': 'product_id'}"
/>
<filter
string=
'Year'
name=
"group_by_year"
domain=
"[]"
context=
"{'group_by' : 'year'}"
/>
</group>
</group>
</search>
</field>
</record>
<record
id=
"tandur_price_hist_search_action"
model=
"ir.actions.act_window"
>
<field
name=
"context"
>
{'default_product_id': active_id, 'search_default_product_id': active_id}
</field>
<field
name=
"name"
>
Price History
</field>
<field
name=
"res_model"
>
tandur.price.hist
</field>
<field
name=
"domain"
>
[]
</field>
<!-- Force empty -->
</record>
<record
id=
"tandur_price_hist_action"
model=
"ir.actions.act_window"
>
<field
name=
"name"
>
History of Price
</field>
<!-- <record id="action_tandur_price_hist_search" model="ir.actions.act_window">-->
<!-- <field name="context">{'default_product_id': active_id, 'search_default_product_id': active_id}</field>-->
<!-- <field name="name">Price History</field>-->
<!-- <field name="res_model">tandur.price.hist</field>-->
<!-- <field name="view_type">form</field>-->
<!-- <field name="domain">[]</field> <!– Force empty –>-->
<!-- </record>-->
<record
id=
"action_tandur_price_hist"
model=
"ir.actions.act_window"
>
<field
name=
"name"
>
History of Price
</field>
<field
name=
"res_model"
>
tandur.price.hist
</field>
<field
name=
"context"
>
{'search_default_group_by_product': 1}
</field>
<field
name=
"view_mode"
>
tree
</field>
<field
name=
"view_mode"
>
tree
,form,graph,pivot
</field>
<field
name=
"search_view_id"
ref=
"view_tandur_price_hist_filter"
/>
<field
name=
"view_id"
ref=
"
tandur_price_hist_view
_tree"
/>
<field
name=
"view_id"
ref=
"
view_tandur_price_hist
_tree"
/>
<field
name=
"help"
type=
"html"
>
<p
class=
"o_view_nocontent_smiling_face"
>
History of Price Not Found
...
...
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