summaryrefslogtreecommitdiff
path: root/indoteknik_custom/models/product_template.py
blob: 348bda99a32c82fd81efe134777ae529cfa115c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
from odoo import fields, models


class ProductTemplate(models.Model):
    _inherit = "product.template"

    x_studio_field_tGhJR = fields.Many2many('x_product_tags', string="Product Tags")
    x_manufacture = fields.Many2one(
        comodel_name="x_manufactures",
        string="Manufactures"
    )
    x_model_product = fields.Char(string="Model Produk")
    x_product_manufacture = fields.Many2one(
        comodel_name="x_manufactures",
        string="Manufacture"
    )
    x_lazada = fields.Text(string="Lazada")
    x_tokopedia = fields.Text(string="Tokopedia")
    web_price = fields.Float(
        'Web Price', compute='_compute_web_price',
        digits='Product Price', inverse='_set_product_lst_price',
        help="Web Price with pricelist_id = 1")

    def _compute_web_price(self):
        for template in self:
            product = self.env['product.product'].search([('product_tmpl_id', '=', template.id)],limit=1)
            product_pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 1),('product_id', '=', product.id)],limit=1)
            template.web_price = product_pricelist_item.fixed_price

class ProductProduct(models.Model):
    _inherit = "product.product"
    web_price = fields.Float(
        'Web Price', compute='_compute_web_price',
        digits='Product Price', inverse='_set_product_lst_price',
        help="Web Price with pricelist_id = 1")
    qty_stock_vendor = fields.Float(
        'Qty Stock Vendor', compute='_compute_stock_vendor',
        help="Stock Vendor")

    def _compute_web_price(self):
        for product in self:
            product_pricelist_item = self.env['product.pricelist.item'].search([('pricelist_id', '=', 1),('product_id', '=', product.id)],limit=1)
            product.web_price = product_pricelist_item.fixed_price

    def _compute_stock_vendor(self):
        for product in self:
            stock_vendor = self.env['stock.vendor'].search([('product_variant_id', '=', product.id)],limit=1)
            product.qty_stock_vendor = stock_vendor.quantity+product.qty_available