summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAzka Nathan <darizkyfaz@gmail.com>2023-09-05 14:45:18 +0700
committerAzka Nathan <darizkyfaz@gmail.com>2023-09-05 14:45:18 +0700
commit513bce9e13dee0453ce24b41a54d3b408e58c7f0 (patch)
tree21426e7af98ad3fcb34101e42ce0979d4472958a
parenta1137c5bb22734eff9585b7b95607983f23d2de9 (diff)
Fix bug solr product variants, add analytic tags to jurnal entries line, remove validation edit di purchase pricelist
-rw-r--r--indoteknik_custom/models/account_account.py3
-rw-r--r--indoteknik_custom/models/account_move_line.py5
-rwxr-xr-xindoteknik_custom/models/product_template.py85
-rwxr-xr-xindoteknik_custom/models/purchase_pricelist.py5
-rw-r--r--indoteknik_custom/models/solr/product_template.py42
-rw-r--r--indoteknik_custom/views/account_account_views.xml3
-rw-r--r--indoteknik_custom/views/account_move_line.xml6
7 files changed, 53 insertions, 96 deletions
diff --git a/indoteknik_custom/models/account_account.py b/indoteknik_custom/models/account_account.py
index e2988625..d8ac3204 100644
--- a/indoteknik_custom/models/account_account.py
+++ b/indoteknik_custom/models/account_account.py
@@ -4,4 +4,5 @@ class AccountAccount(models.Model):
_inherit = 'account.account'
cost_centre_id = fields.Many2one('cost.centre', string='Cost Centre')
- analytic_account_ids = fields.Many2many('account.analytic.account', string='Analytic Account') \ No newline at end of file
+ analytic_tag_ids = fields.Many2many("account.analytic.tag",
+ string="Analytic Tags") \ No newline at end of file
diff --git a/indoteknik_custom/models/account_move_line.py b/indoteknik_custom/models/account_move_line.py
index cb969855..c230b956 100644
--- a/indoteknik_custom/models/account_move_line.py
+++ b/indoteknik_custom/models/account_move_line.py
@@ -6,13 +6,12 @@ class AccountMoveLine(models.Model):
cost_centre_id = fields.Many2one('cost.centre', string='Cost Centre')
is_required = fields.Boolean(string='Is Required', compute='_compute_is_required')
- analytic_account_ids = fields.Many2many('account.analytic.account', string='Analytic Account')
@api.onchange('account_id')
def _onchange_analytic_account_ids(self):
for account in self:
- analytic_account = account.account_id.analytic_account_ids
- account.analytic_account_ids = analytic_account
+ analytic_account = account.account_id.analytic_tag_ids
+ account.analytic_tag_ids = analytic_account
@api.onchange('account_id')
def _compute_is_required(self):
diff --git a/indoteknik_custom/models/product_template.py b/indoteknik_custom/models/product_template.py
index b44f585e..8daa0b7a 100755
--- a/indoteknik_custom/models/product_template.py
+++ b/indoteknik_custom/models/product_template.py
@@ -53,47 +53,37 @@ class ProductTemplate(models.Model):
seq_new_product = fields.Integer(string='Seq New Product', help='Urutan Sequence New Product')
is_edited = fields.Boolean(string='Is Edited')
- # def write(self, vals):
- # if not self.env.user.is_purchasing_manager:
- # for product in self:
-
- # domain = [
- # ('id', '=', product.id),
- # ('create_date', '<=', product.write_date),
- # ('name', '=', product.name),
- # ('default_code', '=', product.default_code)
- # ]
-
- # existing_purchase = self.search(domain, limit=1)
- # if existing_purchase:
- # raise UserError("Hanya Pak Tyas yang bisa mengedit product")
- # return super(ProductTemplate, self).write(vals)
-
- @api.constrains('name','default_code')
+ @api.constrains('name', 'default_code')
def _check_duplicate_product(self):
- if not self.env.user.is_purchasing_manager:
- for product in self:
- if product.write_date == product.create_date:
- domain = [
- ('default_code', '!=', False),
+ for product in self:
+ if not self.env.user.is_purchasing_manager:
+ domain = [('default_code', '!=', False)]
+
+ if product.product_variant_ids:
+ domain.extend([
'|',
- ('name', '=', product.name),
- ('default_code', '=', product.default_code)]
-
- domain.append(('id', '!=', product.id))
- massage="SKU atau Name yang anda pakai sudah digunakan di product lain"
- existing_purchase = self.search(domain, limit=1)
- if existing_purchase:
- raise UserError(massage)
+ ('name', 'in', [variants.name for variants in product.product_variant_ids]),
+ ('default_code', 'in', [variants.default_code for variants in product.product_variant_ids])
+ ])
else:
- domain = [
- ('id', '=', product.id)
- ]
- massage="Hanya Pak Tyas Yang Dapat Merubah Data Product"
- existing_purchase = self.search(domain, limit=1)
- if existing_purchase:
- raise UserError(massage)
-
+ domain.extend([
+ '|',
+ ('name', 'in', [product.name]),
+ ('default_code', 'in', [product.default_code])
+ ])
+
+ domain.append(('id', '!=', product.id))
+
+ if product.write_date == product.create_date:
+ message = "SKU atau Name yang Anda gunakan sudah digunakan di produk lain"
+ else:
+ domain = [('id', '=', product.id)]
+ message = "Hanya Pak Tyas yang dapat merubah data produk"
+
+ existing_purchase = self.search(domain, limit=1)
+
+ if existing_purchase:
+ raise UserError(message)
@api.constrains('name')
def _validate_name(self):
@@ -334,21 +324,6 @@ class ProductProduct(models.Model):
sla_version = fields.Integer(string="SLA Version", default=0)
is_edited = fields.Boolean(string='Is Edited')
- # def write(self, vals):
- # if not self.env.user.is_purchasing_manager:
- # for product in self:
- # domain = [
- # ('id', '=', product.id),
- # ('create_date', '<=', product.write_date),
- # ('name', '=', product.name),
- # ('default_code', '=', product.default_code)
- # ]
-
- # existing_purchase = self.search(domain, limit=1)
- # if existing_purchase:
- # raise UserError("Hanya Pak Tyas yang bisa mengedit product")
- # return super(ProductProduct, self).write(vals)
-
@api.constrains('name','default_code')
def _check_duplicate_product(self):
if not self.env.user.is_purchasing_manager:
@@ -357,8 +332,8 @@ class ProductProduct(models.Model):
domain = [
('default_code', '!=', False),
'|',
- ('name', '=', product.name),
- ('default_code', '=', product.default_code)]
+ ('name', 'in', [template.name for template in product.product_tmpl_id] or [product.name]),
+ ('default_code', 'in', [template.default_code for template in product.product_tmpl_id] or [product.default_code])]
domain.append(('id', '!=', product.id))
massage="SKU atau Name yang anda pakai sudah digunakan di product lain"
diff --git a/indoteknik_custom/models/purchase_pricelist.py b/indoteknik_custom/models/purchase_pricelist.py
index 5d077e04..86a5544d 100755
--- a/indoteknik_custom/models/purchase_pricelist.py
+++ b/indoteknik_custom/models/purchase_pricelist.py
@@ -42,11 +42,6 @@ class PurchasePricelist(models.Model):
existing_purchase = self.search(domain, limit=1)
if existing_purchase:
raise UserError(massage)
- else:
- domain = [
- ('id', '=', price.id)
- ]
- massage="Tidak Dapat Merubah Product"
existing_purchase = self.search(domain, limit=1)
if existing_purchase:
raise UserError(massage) \ No newline at end of file
diff --git a/indoteknik_custom/models/solr/product_template.py b/indoteknik_custom/models/solr/product_template.py
index 63daeb46..9950c93a 100644
--- a/indoteknik_custom/models/solr/product_template.py
+++ b/indoteknik_custom/models/solr/product_template.py
@@ -104,35 +104,25 @@ class ProductTemplate(models.Model):
solr = self.solr()
for template in self:
- price_excl_after_disc = price_excl = discount = tax = 0
- flashsale_data = tier1 = tier2 = tier3 = {}
+ document = solr_model.get_doc('product', template.id)
+ flashsale_data = {}
for variant in template.product_variant_ids:
- if price_excl_after_disc == 0 or variant._get_website_price_after_disc_and_tax() < price_excl_after_disc:
- variant_flashsale = variant._get_flashsale_price()
- flashsale_price = flashsale_data.get('flashsale_price')
- if not flashsale_price or variant_flashsale['flashsale_price'] < flashsale_data.get('flashsale_price', 0):
- flashsale_data = variant_flashsale
- price_excl = variant._get_website_price_exclude_tax()
- price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
- discount = variant._get_website_disc(0)
- tax = variant._get_website_tax()
- # add price tiering for base price, discount, and price after discount (tier 1 - 3)
- tier1 = variant._get_pricelist_tier1()
- tier2 = variant._get_pricelist_tier2()
- tier3 = variant._get_pricelist_tier3()
-
- if template.product_variant_count == 1:
- price_excl = template.product_variant_id._get_website_price_exclude_tax()
- discount = template.product_variant_id._get_website_disc(0)
- price_excl_after_disc = template.product_variant_id._get_website_price_after_disc_and_tax()
- tax = template.product_variant_id._get_website_tax()
- flashsale_data = template.product_variant_id._get_flashsale_price()
- tier1 = template.product_variant_id._get_pricelist_tier1()
- tier2 = template.product_variant_id._get_pricelist_tier2()
- tier3 = template.product_variant_id._get_pricelist_tier3()
+ variant_flashsale = variant._get_flashsale_price()
+ variant_flashsale_price = variant_flashsale.get('flashsale_price', 0)
+ flashsale_data_price = flashsale_data.get('flashsale_price', 0)
+
+ if flashsale_data_price == 0 or (variant_flashsale_price != 0 and variant_flashsale_price < flashsale_data_price):
+ flashsale_data = variant_flashsale
+
+ price_excl = variant._get_website_price_exclude_tax()
+ price_excl_after_disc = variant._get_website_price_after_disc_and_tax()
+ discount = variant._get_website_disc(0)
+ tax = variant._get_website_tax()
+ tier1 = variant._get_pricelist_tier1()
+ tier2 = variant._get_pricelist_tier2()
+ tier3 = variant._get_pricelist_tier3()
- document = solr_model.get_doc('product', template.id)
document.update({
'id': template.id,
'flashsale_id_i': flashsale_data.get('flashsale_id', 0),
diff --git a/indoteknik_custom/views/account_account_views.xml b/indoteknik_custom/views/account_account_views.xml
index 20886787..875d5a6b 100644
--- a/indoteknik_custom/views/account_account_views.xml
+++ b/indoteknik_custom/views/account_account_views.xml
@@ -7,8 +7,7 @@
<field name="inherit_id" ref="account.view_account_list"/>
<field name="arch" type="xml">
<field name="currency_id" position="after">
- <field name="cost_centre_id" optional="hide"/>
- <field name="analytic_account_ids" widget="many2many_tags" options="{'no_create': True}"/>
+ <field name="analytic_tag_ids" optional="show" widget="many2many_tags"/>
</field>
</field>
</record>
diff --git a/indoteknik_custom/views/account_move_line.xml b/indoteknik_custom/views/account_move_line.xml
index 99122de3..5b5f73cd 100644
--- a/indoteknik_custom/views/account_move_line.xml
+++ b/indoteknik_custom/views/account_move_line.xml
@@ -8,11 +8,9 @@
<field name="arch" type="xml">
<xpath expr="//page[@id='aml_tab']/field[@name='line_ids']/tree/field[@name='currency_id']" position="before">
<field name="is_required" invisible="1"/>
- <field name="cost_centre_id" optional="hide"/>
- <field name="analytic_account_ids" widget="many2many_tags" options="{'no_create': True}"/>
</xpath>
- <xpath expr="//page[@id='aml_tab']/field[@name='line_ids']/tree/field[@name='analytic_account_id']" position="attributes">
- <attribute name="invisible">1</attribute>
+ <xpath expr="//page[@id='aml_tab']/field[@name='line_ids']/tree/field[@name='analytic_tag_ids']" position="attributes">
+ <attribute name="groups"/>
</xpath>
</field>
</record>