@@ -1,3 +1,4 @@
|
||||
* Add relate to open products from sale
|
||||
|
||||
Version 7.4.0 - 2024-11-04
|
||||
--------------------------
|
||||
|
||||
@@ -61,6 +61,7 @@ def register():
|
||||
sale.HandleInvoiceException,
|
||||
sale.ReturnSale,
|
||||
sale.ModifyHeader,
|
||||
sale.OpenProduct,
|
||||
party.Replace,
|
||||
party.Erase,
|
||||
sale_reporting.OpenRegionTree,
|
||||
|
||||
+27
-8
@@ -242,10 +242,13 @@ class SaleContext(ModelView):
|
||||
def default_locations(cls):
|
||||
pool = Pool()
|
||||
Location = pool.get('stock.location')
|
||||
locations = []
|
||||
warehouse = Location.get_default_warehouse()
|
||||
if warehouse:
|
||||
locations.append(warehouse)
|
||||
context = Transaction().context
|
||||
locations = context.get('locations')
|
||||
if locations is None:
|
||||
locations = []
|
||||
warehouse = Location.get_default_warehouse()
|
||||
if warehouse:
|
||||
locations.append(warehouse)
|
||||
return locations
|
||||
|
||||
@classmethod
|
||||
@@ -256,10 +259,26 @@ class SaleContext(ModelView):
|
||||
def default_currency(cls):
|
||||
pool = Pool()
|
||||
Company = pool.get('company.company')
|
||||
company_id = cls.default_company()
|
||||
if company_id:
|
||||
company = Company(company_id)
|
||||
return company.currency.id
|
||||
context = Transaction().context
|
||||
currency = context.get('currency')
|
||||
if currency is None:
|
||||
company_id = cls.default_company()
|
||||
if company_id:
|
||||
company = Company(company_id)
|
||||
currency = company.currency.id
|
||||
return currency
|
||||
|
||||
@classmethod
|
||||
def default_customer(cls):
|
||||
return Transaction().context.get('customer')
|
||||
|
||||
@classmethod
|
||||
def default_sale_date(cls):
|
||||
return Transaction().context.get('sale_date')
|
||||
|
||||
@classmethod
|
||||
def default_quantity(cls):
|
||||
return Transaction().context.get('quantity')
|
||||
|
||||
@fields.depends('sale_date')
|
||||
def on_change_with_stock_date_end(self, name=None):
|
||||
|
||||
+48
-1
@@ -25,7 +25,7 @@ from trytond.modules.company.model import (
|
||||
from trytond.modules.currency.fields import Monetary
|
||||
from trytond.modules.product import price_digits
|
||||
from trytond.pool import Pool
|
||||
from trytond.pyson import Bool, Eval, If
|
||||
from trytond.pyson import Bool, Eval, If, PYSONEncoder
|
||||
from trytond.tools import cached_property, firstline, sortable_values
|
||||
from trytond.transaction import Transaction
|
||||
from trytond.wizard import (
|
||||
@@ -2467,3 +2467,50 @@ class ModifyHeader(Wizard):
|
||||
Line.save(sale.lines)
|
||||
|
||||
return 'end'
|
||||
|
||||
|
||||
class OpenProduct(Wizard):
|
||||
__name__ = 'sale.open_product'
|
||||
|
||||
start = StateAction('sale.act_product')
|
||||
|
||||
def _context(self):
|
||||
context = {
|
||||
'stock_skip_warehouse': True,
|
||||
'locations': [],
|
||||
}
|
||||
companies = set()
|
||||
currencies = set()
|
||||
customers = set()
|
||||
sale_dates = set()
|
||||
for record in self.records:
|
||||
companies.add(record.company.id)
|
||||
currencies.add(record.currency.id)
|
||||
customers.add(record.party.id)
|
||||
sale_dates.add(record.sale_date)
|
||||
if self.record.warehouse:
|
||||
context['locations'].append(self.record.warehouse.id)
|
||||
if len(companies) == 1:
|
||||
context['company'], = companies
|
||||
if len(currencies) == 1:
|
||||
context['currency'], = currencies
|
||||
if len(customers) == 1:
|
||||
context['customer'], = customers
|
||||
if len(sale_dates) == 1:
|
||||
context['sale_date'], = sale_dates
|
||||
return context
|
||||
|
||||
def do_start(self, action):
|
||||
product_ids = {
|
||||
l.product.id for r in self.records for l in r.lines if l.product}
|
||||
encoder = PYSONEncoder()
|
||||
domain = [
|
||||
('id', 'in', list(product_ids)),
|
||||
]
|
||||
action['pyson_domain'] = encoder.encode(domain)
|
||||
action['pyson_context'] = encoder.encode(self._context())
|
||||
name_suffix = ', '.join(r.rec_name for r in self.records[:5])
|
||||
if len(self.records) > 5:
|
||||
name_suffix += ',...'
|
||||
action['name'] += f' ({name_suffix})'
|
||||
return action, {}
|
||||
|
||||
@@ -542,5 +542,16 @@ this repository contains the full copyright notices and license terms. -->
|
||||
eval="Eval('context', {}).get('modify_header', False)"
|
||||
pyson="1"/>
|
||||
</record>
|
||||
|
||||
<record model="ir.action.wizard" id="wizard_sale_open_product">
|
||||
<field name="name">Products</field>
|
||||
<field name="wiz_name">sale.open_product</field>
|
||||
<field name="model">sale.sale</field>
|
||||
</record>
|
||||
<record model="ir.action.keyword" id="wizard_sale_open_product_keyword1">
|
||||
<field name="keyword">form_relate</field>
|
||||
<field name="model">sale.sale,-1</field>
|
||||
<field name="action" ref="wizard_sale_open_product"/>
|
||||
</record>
|
||||
</data>
|
||||
</tryton>
|
||||
|
||||
@@ -18,3 +18,6 @@ def register():
|
||||
configuration.Configuration,
|
||||
configuration.ConfigurationSalePriceList,
|
||||
module='sale_price_list', type_='model')
|
||||
Pool.register(
|
||||
sale.OpenProduct,
|
||||
module='sale_price_list', type_='wizard')
|
||||
|
||||
@@ -63,10 +63,14 @@ class SaleContext(metaclass=PoolMeta):
|
||||
def default_price_list(cls, **pattern):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('sale.configuration')
|
||||
config = Configuration(1)
|
||||
price_list = config.get_multivalue('sale_price_list', **pattern)
|
||||
if price_list:
|
||||
return price_list.id
|
||||
context = Transaction().context
|
||||
price_list = context.get('price_list')
|
||||
if price_list is None:
|
||||
config = Configuration(1)
|
||||
price_list = config.get_multivalue('sale_price_list', **pattern)
|
||||
if price_list:
|
||||
price_list = price_list.id
|
||||
return price_list
|
||||
|
||||
@fields.depends(methods=['on_change_customer'])
|
||||
def on_change_company(self):
|
||||
|
||||
@@ -66,3 +66,16 @@ class Line(metaclass=PoolMeta):
|
||||
if getattr(self.sale, 'price_list', None):
|
||||
context['price_list'] = self.sale.price_list.id
|
||||
return context
|
||||
|
||||
|
||||
class OpenProduct(metaclass=PoolMeta):
|
||||
__name__ = 'sale.open_product'
|
||||
|
||||
def _context(self):
|
||||
context = super()._context()
|
||||
price_lists = {r.price_list for r in self.records}
|
||||
if len(price_lists) == 1:
|
||||
price_list, = price_lists
|
||||
if price_list:
|
||||
context['price_list'] = price_list.id
|
||||
return context
|
||||
|
||||
Reference in New Issue
Block a user