Beispiel #1
0
    def _compute_default_purchase_price(self):
        for p in pb(self):
            if isinstance(p.id, models.NewId):
                continue
            if p.seller_id:
                history = {}
                pricelist = p.seller_id.property_product_pricelist_purchase.\
                    with_context(history=history)
                if pricelist:
                    p.default_purchase_price = \
                        pricelist.get_product_price(
                            p, 1, False, uom_id=p.uom_id.id
                        )
                    graph = history[p.id]['graph']['header'] + \
                            history[p.id]['graph']['body']
                    p.default_purchase_price_graph = '\n'.join(graph)

                    history.clear()
                    p.default_purchase_price_po_uom = \
                        pricelist.get_product_price(
                            p, 1, False, uom_id=p.uom_po_id.id
                        )
                    graph = history[p.id]['graph']['header'] + \
                            history[p.id]['graph']['body']
                    p.default_purchase_price_graph_po_uom = '\n'.join(graph)
            else:
                p.default_purchase_price = p.standard_price
                p.default_purchase_price_graph = False
                p.default_purchase_price_po_uom = p.standard_price_po_uom
                p.default_purchase_price_graph_po_uom = False
 def update_default_purchase_price(self):
     ''' Store default purchase prices which can be computed
         using different pricelist rules
     '''
     for rec in pb(self):
         rec.update_purchase_price(
             rec.default_purchase_price, fields.Datetime.now()
         )
 def update_default_sell_price(self):
     ''' Store default sell prices which can be computed
         using different pricelist rules
     '''
     product_ids = self.with_context(active_test=False)\
         .mapped('product_variant_ids')
     for rec in pb(product_ids):
         rec.update_sell_price(rec.default_sell_price,
                               fields.Datetime.now())
    def _update_default_prices(self, product_ids):
        SPLIT = 500
        search_domain = [
            ('id', 'in', product_ids),
            ('type', '=', 'product'),
        ]

        products = self.search(
            search_domain + [
                ('|'),
                ('purchase_ok', '=', True),
                ('sale_ok', '=', True),
            ]
        )
        idx = 0
        for ids in pb(list(split_every(SPLIT, products.ids))):
            _logger.info(
                'Processing (%d -> %d)/%d', idx,
                min(idx + SPLIT, len(products.ids)), len(products.ids)
            )
            idx += SPLIT
            self.browse(ids).update_default_purchase_price()
            self.env.cr.commit()

        products = self.search(search_domain + [
            ('sale_ok', '=', True),
        ])
        idx = 0
        for ids in pb(list(split_every(SPLIT, products.ids))):
            _logger.info(
                'Processing (%d -> %d)/%d', idx,
                min(idx + SPLIT, len(products.ids)), len(products.ids)
            )
            idx += SPLIT
            self.browse(ids).update_default_sell_price()
            self.env.cr.commit()
Beispiel #5
0
 def _compute_default_sell_price(self):
     for p in pb(self):
         if isinstance(p.id, models.NewId):
             continue
         if p.company_id and p.company_id.partner_id:
             history = {}
             pricelist = p.company_id.partner_id.\
                 property_product_pricelist.with_context(history=history)
             if pricelist:
                 p.default_sell_price = \
                     pricelist.get_product_price(
                         p, 1, False, uom_id=p.uom_id.id
                     )
                 graph = history[p.id]['graph']['header'] + \
                         history[p.id]['graph']['body']
                 p.default_sell_price_graph = '\n'.join(graph)
         else:
             p.default_sell_price = p.list_price
             p.default_sell_price_graph = False
 def action_split_by_zip(self):
     for rec in pb(self):
         if len(rec.zip_ids) <= 1:
             continue
         common_prefix = False
         to_split = {}
         for zip_id in rec.zip_ids:
             if len(zip_id.name) >= 2:
                 other_prefix = zip_id.name[:2]
                 if not common_prefix:
                     common_prefix = other_prefix
                 elif other_prefix != common_prefix:
                     if not other_prefix in to_split:
                         to_split[other_prefix] = []
                     to_split[other_prefix].append(zip_id)
         if not to_split:
             continue
         for prefix, zip_ids in to_split.items():
             new_city_id = rec.copy(default={'zip_ids': False})
             for zip_id in zip_ids:
                 zip_id.city_id = new_city_id
Beispiel #7
0
 def action_set_default_analytic_account(self):
     for rec in pb(self):
         rec._set_default_analytic_account()