Beispiel #1
0
class Product(metaclass=PoolMeta):
    __name__ = 'product.product'
    account_stock_used = template_property('account_stock_used')
    account_stock_supplier_used = template_property(
        'account_stock_supplier_used')
    account_stock_customer_used = template_property(
        'account_stock_customer_used')
    account_stock_production_used = template_property(
        'account_stock_production_used')
    account_stock_lost_found_used = template_property(
        'account_stock_lost_found_used')
Beispiel #2
0
class Product:
    __metaclass__ = PoolMeta
    __name__ = 'product.product'
    account_cogs_used = template_property('account_cogs_used')
class Product(metaclass=PoolMeta):
    __name__ = 'product.product'
    account_stock_used = template_property('account_stock_used')
    account_stock_in_used = template_property('account_stock_in_used')
    account_stock_out_used = template_property('account_stock_out_used')

    @classmethod
    def update_cost_price(cls, costs):
        pool = Pool()
        Date = pool.get('ir.date')
        Stock = pool.get('stock.location')
        Company = pool.get('company.company')
        Move = pool.get('account.move')

        context = Transaction().context
        locations = Stock.search([('type', '=', 'storage')])
        company = Company(context['company'])
        with Transaction().set_context(company=company.id):
            stock_date_end = Date.today()
        moves = []
        with Transaction().set_context(locations=[l.id for l in locations],
                stock_date_end=stock_date_end):
            for cost, products in costs.items():
                products = cls.browse(products)
                for product in products:
                    difference = cost - product.cost_price
                    quantity = product.quantity
                    amount = company.currency.round(
                        Decimal(str(quantity)) * difference)
                    if amount:
                        moves.append(product._update_cost_price_move(
                                amount, company))
        Move.save(moves)
        Move.post(moves)
        super().update_cost_price(costs)

    def _update_cost_price_move(self, amount, company):
        pool = Pool()
        AccountConfiguration = pool.get('account.configuration')
        Date = pool.get('ir.date')
        Period = pool.get('account.period')
        Move = pool.get('account.move')
        Line = pool.get('account.move.line')

        config = AccountConfiguration(1)
        if amount > 0:
            account = self.account_stock_in_used
        else:
            account = self.account_stock_out_used
        with Transaction().set_context(company=company.id):
            today = Date.today()
        return Move(
            period=Period.find(company.id),
            journal=config.stock_journal,
            date=today,
            origin=self,
            lines=[Line(
                    debit=amount if amount > 0 else 0,
                    credit=-amount if amount < 0 else 0,
                    account=self.account_stock_used,
                    ),
                Line(
                    debit=-amount if amount < 0 else 0,
                    credit=amount if amount > 0 else 0,
                    account=account,
                    ),
                ],
            )
Beispiel #4
0
class Product:
    __metaclass__ = PoolMeta
    __name__ = 'product.product'

    account_depreciation_used = template_property('account_depreciation_used')
    account_asset_used = template_property('account_asset_used')