Commit b2869fc2 by aa.gusti

penambahan wp_id pada product

1 parent e2f7cd02
import base64
import io
import logging
import os
from random import randrange
from PIL import Image
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 PIL import Image
import logging
_logger = logging.getLogger(__name__)
TYPE_LIST = [('hotel', 'Hotel'),
......@@ -43,11 +41,23 @@ class Product(models.Model):
'abt': 'set default',
'parkir': 'set default'
})
partner_id = fields.Many2one('res.partner', string="Partner Related")
# wp_name = fields.Many2one(
# 'res.partner', compute='_compute_wp', inverse='_inverse_wp_name',
# string="Nama")
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())
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(
'res.district', compute='_compute_address', inverse='_inverse_district',
string="Kab/Kota", domain="[('state_id', '=?', state_id)]",
......@@ -62,15 +72,41 @@ class Product(models.Model):
'res.district.village', compute='_compute_address', inverse='_inverse_village',
string="Desa/Kelurahan", domain="[('sub_district_id', '=?', sub_district_id)]"
)
company_id = fields.Many2one('res.company', related='partner_id.company_id',
string='Lembaga/Organisasi', required=True,
store=True, readonly=False,
default=lambda self: self.env.company.id
if not self.company_id else False
)
wp_id = fields.Many2one(
'res.partner', compute='_compute_wp', inverse='_inverse_wp_id',
string="Wajib Pajak", store=False)
company_id = fields.Many2one(
'res.company', related='partner_id.company_id', string='Lembaga/Organisasi',
default=lambda self: self.env.company.id if not self.company_id else False,
required=False, store=True, readonly=False,
)
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)
@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_street2 = fields.Char(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):
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_zip = fields.Char(compute='_compute_wp', string="ZIP")
wp_phone = fields.Char(compute='_compute_wp', string="Phone")
wp_email = fields.Char(compute='_compute_wp', string="Email")
wp_phone = fields.Char(compute='_compute_wp', string="Phone")
wp_email = fields.Char(compute='_compute_wp', string="Email")
wp_website = fields.Char(compute='_compute_wp', string="Web Site")
rate = fields.Float(related='categ_id.rate', store=True, readonly=False)
# Prosesing Wajib Pajak
def _get_wp_address_field_names(self):
return [
("wp_id", "id"),
# ("wp_id", "id"),
("wp_street", "street"),
("wp_street2", "street2"),
("wp_village_id", "village_id"),
......@@ -108,15 +145,16 @@ class Product(models.Model):
return field
def _compute_wp(self):
for wp in self.filtered(lambda product: product.partner_id):
if not wp.partner_id:
continue
address_data = wp.partner_id.parent_id.sudo().address_get(adr_pref=['wp'])
if address_data['wp']:
partner = wp.partner_id.browse(address_data['wp']).sudo()
wp.update(wp._get_wp_address_update(partner))
else:
wp.update(wp._get_wp_address_update(False))
if self.wp_id:
for product in self.filtered(lambda product: product.wp_id):
address_data = product.wp_id.sudo().address_get(adr_pref=['wp'])
if address_data['wp']:
partner = product.partner_id.browse(address_data['wp']).sudo()
product.update(product._get_wp_address_update(partner))
else:
product.update(product._get_wp_address_update(False))
else:
self.update(self._get_wp_address_update(False))
@api.onchange('wp_id')
def _onchange_wp_id(self):
......@@ -132,12 +170,7 @@ class Product(models.Model):
self.wp_website = self.wp_id.website
def copy(self, default=None):
raise UserError(_('Duplicating a company is not allowed. Please create a new company 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())
raise UserError(_('Duplicating a object pajak is not allowed. Please create a new object pajak instead.'))
def _get_default_favicon(self, original=False):
img_path = get_resource_path('web', 'static/src/img/favicon.ico')
......@@ -165,44 +198,6 @@ class Product(models.Model):
new_image.save(stream, format="ICO")
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
def _inverse_wp_id(self):
for product in self:
......
<?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>
......@@ -11,7 +11,8 @@
<!-- <field name="lst_price" string="Min Omset"/>-->
<field name="wp_id" string="Wajib Pajak"/>
<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>
</field>
</record>
......@@ -72,10 +73,10 @@
<field name="wp_id" string="Wajib Pajak" domain="[('type','=', 'wp')]"
options='{"no_open": False}'
context="{'default_type': 'wp', 'readonly_type':True}"/>
<!-- <field name="wp_name" class="o_address_street"/>-->
<label for="street" string="Address"/>
<div class="o_address_format">
<field name="wp_street" placeholder="Street..." class="o_address_street"
readonly="1" required="0"/>
<field name="wp_street" placeholder="Street..." 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"
options='{"no_open": True}'/>
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!